示例#1
0
 /**
  * Handles the connection authentication.
  *
  * @param ConnectionInterface $connection
  * @param Payload $payload
  */
 protected function handleAuthentication(ConnectionInterface $connection, Payload $payload)
 {
     if (!$this->connectionManager->authenticate($connection, $payload->getData())) {
         $connection->emit(new Payload(ConnectionEvent::SOCKET_AUTH_FAILURE, 'Invalid access token.'));
         $this->eventDispatcher->dispatch(ConnectionEvent::SOCKET_AUTH_FAILURE, new ConnectionEvent($connection));
         $this->logger->notice(sprintf('Authentication error <info>#%s</info> (<comment>%s</comment>)', $connection->getId(), $connection->getRemoteAddress()));
         return;
     }
     $response = new Payload(ConnectionEvent::SOCKET_AUTH_SUCCESS, $connection->getClient()->jsonSerialize());
     $connection->emit($response);
     $this->eventDispatcher->dispatch(ConnectionEvent::SOCKET_AUTH_SUCCESS, new ConnectionEvent($connection));
     $this->logger->notice(sprintf('Authenticated <info>#%s</info> (<comment>%s</comment>)', $connection->getId(), $connection->getRemoteAddress()));
 }
示例#2
0
 /**
  * Emits an event to this connection with the given payload.
  *
  * @param Payload $payload
  *
  * @return boolean
  */
 public function emit(Payload $payload)
 {
     $this->connection->send($payload->encode());
 }