Beispiel #1
0
 private function getWebSocketUri(Identifier $identifier, string $fKey)
 {
     $authBody = (new FormBody())->addField("roomid", $identifier->getId())->addField("fkey", $fKey);
     $historyBody = (new FormBody())->addField('since', 0)->addField('mode', 'Messages')->addField("msgCount", 1)->addField("fkey", $fKey);
     $requests = ['auth' => (new HttpRequest())->setUri($this->urlResolver->getEndpointURL($identifier, Endpoint::CHATROOM_WEBSOCKET_AUTH))->setMethod("POST")->setBody($authBody), 'history' => (new HttpRequest())->setUri($this->urlResolver->getEndpointURL($identifier, Endpoint::CHATROOM_EVENT_HISTORY))->setMethod("POST")->setBody($historyBody)];
     /** @var HttpResponse[] $responses */
     $responses = (yield all($this->httpClient->requestMulti($requests)));
     $authInfo = json_try_decode($responses['auth']->getBody(), true);
     $historyInfo = json_try_decode($responses['history']->getBody(), true);
     if (!isset($authInfo['url'])) {
         throw new \RuntimeException("WebSocket auth did not return URL");
     }
     if (!isset($historyInfo['time'])) {
         throw new \RuntimeException("Could not get time for WebSocket URL");
     }
     return $authInfo['url'] . '?l=' . $historyInfo['time'];
 }
Beispiel #2
0
 public function equals(Identifier $identifier) : bool
 {
     return $this->host === $identifier->getHost() && $this->id === $identifier->getId();
 }