Exemplo n.º 1
0
 public function isApproved(Identifier $identifier) : Promise
 {
     return isset($this->permanentRooms[$identifier->getIdentString()]) ? new Success(true) : $this->enqueueAction([$this, 'checkIfRoomIsApproved'], $identifier);
 }
Exemplo n.º 2
0
 public function build(Identifier $identifier, Session $session, Handler $handler, PresenceManager $presenceManager, bool $permanent)
 {
     $keyValueStore = $this->keyValueStorageFactory->build($identifier->getIdentString());
     return new Room($identifier, $session, $handler, $presenceManager, $keyValueStore, $permanent);
 }
Exemplo n.º 3
0
 public function equals(Identifier $identifier) : bool
 {
     return $this->host === $identifier->getHost() && $this->id === $identifier->getId();
 }
Exemplo n.º 4
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'];
 }
Exemplo n.º 5
0
 public function isApproved(ChatRoomIdentifier $identifier) : Promise
 {
     return resolve(function () use($identifier) {
         $data = (yield $this->accessor->read($this->dataFileTemplate));
         return $data[$identifier->getIdentString()]['is_approved'] ?? false;
     });
 }