public function fallback(Request $request, Response $response) { $this->writeResponse($request, $response, Error::make("not_found")); }
protected function onMessage($clientId, $data) { if (is_array($data)) { foreach ($data as $message) { (yield resolve($this->onMessage($clientId, $message))); } } else { if (!$this->isValidPayload($data)) { $this->writeResponse($clientId, $data->request_id ?? null, new Error("invalid_request", "invalid payload received", 400)); return; } if ($data->endpoint === "subscribe" && is_int($data->args->room_id)) { $this->rooms[$data->args->room_id][$clientId] = true; $this->writeResponse($clientId, $data->request_id, new Data("success")); return; } $data->args = $data->args ?? new stdClass(); if (!$data->args instanceof stdClass) { $this->writeResponse($clientId, $data->request_id, Error::make("bad_request")); } $sessionId = $this->client2session[$clientId]; $session = $this->sessions[$sessionId]; $user = new User($session->get("login") ?? 0, $session->get("login:name") ?? "", $session->get("login:avatar") ?? null); $request = new StandardRequest($data->endpoint, $data->args, $data->payload ?? null); $response = (yield $this->chat->process($request, $user)); $this->writeResponse($clientId, $data->request_id, $response); } }