/**
  * Get the rooms basic information (name, type, usersMax, usersConnected)
  *
  * @param      Client          $client  The client
  * @param      RoomCollection  $rooms   The rooms
  *
  * @return     \Generator
  */
 private function getAll(Client $client, RoomCollection $rooms)
 {
     $roomsInfo = [];
     foreach ($rooms as $room) {
         $roomsInfo[] = ['room' => $room->getRoomBasicAttributes(), 'connectedClients' => count($room->getClients())];
     }
     (yield $client->getConnection()->send(json_encode(['service' => $this->serviceName, 'action' => 'getAll', 'rooms' => $roomsInfo])));
 }
 /**
  * Determine if a client is banned
  *
  * @param      Client  $client  The client to test
  *
  * @return     bool    True if the client is banned, false otherwise
  */
 public function isClientBanned(Client $client) : bool
 {
     return static::inSubArray($client->getConnection()->getRemoteAddress(), $this->room->getRoomBanCollection(), 'ip');
 }
 /**
  * Get a room historic for a specific room ID and with message date lower than the given value
  *
  * @param      int     $roomId  The room ID to search messages in
  * @param      Client  $client  The client who asked the historic
  * @param      string  $from    The maximum message published date in UNIX micro timestamp (string) DEFAULT null
  *
  * @return     array  The list of messages found
  */
 private function getRoomHistoric(int $roomId, Client $client, string $from = null)
 {
     $es = EsClientBuilder::create()->build();
     $from = $from ?? static::microtimeAsInt();
     $userIp = $client->getConnection()->getRemoteAddress();
     $userId = -1;
     if ($client->getUser() !== null) {
         $userId = $client->getUser()->id;
     }
     return static::filterEsHitsByArray($es->search(['index' => $this->esIndex . '_read', 'type' => 'message', 'sort' => 'date:desc', 'fields' => 'pseudonym,message,type,date', 'size' => $this->historicStep, 'body' => ['query' => ['filtered' => ['filter' => ['bool' => ['must' => [['range' => ['date' => ['lt' => $from]]], ['term' => ['room' => $roomId]], ['bool' => ['should' => [['term' => ['type' => 'public']], ['bool' => ['should' => [['term' => ['userTo.id' => $userId]], ['term' => ['userTo.ip' => $userIp]]]]]]]]]]]]]]]));
 }