Exemplo n.º 1
0
 /**
  * @param Connection $client
  */
 private function _sendServerinfo($client)
 {
     if (count($this->_clients) < 1) {
         return false;
     }
     $currentServerInfo = $this->_serverInfo;
     $currentServerInfo['clientCount'] = count($this->_serverClients);
     $currentServerInfo['clients'] = $this->_serverClients;
     $encodedData = $this->_encodeData('serverInfo', $currentServerInfo);
     $client->send($encodedData);
 }
Exemplo n.º 2
0
 /**
  * Removes a connection
  *
  * @param Connection $connection
  */
 public function removeConnection(Connection $connection)
 {
     $socket = $connection->getSocket();
     if ($socket->getResource()) {
         $index = $socket->getResourceId();
     } else {
         $index = array_search($connection, $this->connections);
     }
     if (!$index) {
         $this->log('Could not remove connection: not found', 'warning');
     }
     unset($this->connections[$index]);
     unset($this->resources[$index]);
     $this->server->notify(Server::EVENT_SOCKET_DISCONNECT, array($connection->getSocket(), $connection));
 }
Exemplo n.º 3
0
 public function isClientSubscribed(Connection $client)
 {
     return array_key_exists($client->getId(), $this->clients);
 }
 /**
  * Logs an application error
  *
  * @see Varspool\WebsocketBundle\Application.Application::log()
  */
 public function log($message, $level = 'info', Connection $client = null)
 {
     if ($this->debug) {
         parent::log($message, $level);
         if ($this->remoteLogging) {
             $log = new stdClass();
             $log->type = 'log';
             $log->level = $level;
             $log->message = $message;
             $log = $this->getJsonPayload($log);
             if ($client) {
                 $client->send(Protocol::toString(Protocol::TYPE_MESSAGE, self::TOPIC_LOG_SERVER, $log));
             } else {
                 $this->getChannel(self::TOPIC_LOG_SERVER)->send($log);
             }
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Handshake request listener
  *
  * Closes the connection on handshake from an origin that isn't allowed
  *
  * @param Connection $connection
  * @param string $path
  * @param string $origin
  * @param string $key
  * @param array $extensions
  */
 public function onHandshakeRequest(Connection $connection, $path, $origin, $key, $extensions)
 {
     if (!$this->isAllowed($origin)) {
         $connection->close(new InvalidOriginException('Origin not allowed'));
     }
 }