Example #1
0
 /**
  * Broadcasts an event to all
  *
  * @param Payload $payload
  * @return mixed
  */
 public function broadcast(Payload $payload)
 {
     foreach ($this->connectionManager->getConnections() as $connection) {
         if ($connection->getId() !== $this->getId()) {
             $connection->emit($payload);
         }
     }
 }
Example #2
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()));
 }