Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 function onOpen(ConnectionInterface $conn)
 {
     if ($this->isBlocked($conn->remoteAddress)) {
         return $conn->close();
     }
     return $this->_decorating->onOpen($conn);
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 function onOpen(ConnectionInterface $conn, $request = null)
 {
     $conn->Config = $this->config;
     if (isset($conn->WebSocket)) {
         //get room from query string
         $room = (int) $conn->WebSocket->request->getQuery()->get('room');
         if (null == $room) {
             $room = 0;
         }
         $conn->Room = $room;
         $this->_createAuthAdapter($room);
         $userInfo = $this->_authAdapter->authUser($conn, $conn->WebSocket->request->getCookies());
         if ($userInfo) {
             $operators = null;
             if (isset($this->config['rooms']) && isset($this->config['rooms'][$room]) && isset($this->config['rooms'][$room]['operators'])) {
                 $operators = $this->config['rooms'][$room]['operators'];
             } else {
                 if ($this->config['operators']) {
                     $operators = $this->config['operators'];
                 }
             }
             //set if operator
             if (!array_key_exists('operator', $userInfo)) {
                 if (!isset($operators)) {
                     $userInfo['operator'] = true;
                 } else {
                     $userInfo['operator'] = in_array($userInfo['id'], $operators);
                 }
             }
             $conn->User = $userInfo;
         }
     }
     return $this->_app->onOpen($conn);
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function onOpen(ConnectionInterface $conn, RequestInterface $request = null)
 {
     $header = (string) $request->getHeader('Origin');
     $origin = parse_url($header, PHP_URL_HOST) ?: $header;
     if (!in_array($origin, $this->allowedOrigins)) {
         return $this->close($conn, 403);
     }
     return $this->_component->onOpen($conn, $request);
 }
Ejemplo n.º 4
0
 /**
  * Triggered when a new connection is received from React
  * @param \React\Socket\ConnectionInterface $conn
  */
 public function handleConnect($conn)
 {
     $conn->decor = new IoConnection($conn);
     $conn->decor->resourceId = (int) $conn->stream;
     $conn->decor->remoteAddress = $conn->getRemoteAddress();
     $this->app->onOpen($conn->decor);
     $conn->on('data', $this->handlers[0]);
     $conn->on('end', $this->handlers[1]);
     $conn->on('error', $this->handlers[2]);
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 function onOpen(ConnectionInterface $conn)
 {
     if (null === ($id = $conn->WebSocket->request->getCookie(ini_get('session.name')))) {
         $saveHandler = $this->_null;
         $id = '';
     } else {
         $saveHandler = $this->_handler;
     }
     $conn->Session = new Session(new VirtualSessionStorage($saveHandler, $id, $this->_serializer));
     if (ini_get('session.auto_start')) {
         $conn->Session->start();
     }
     return $this->_app->onOpen($conn);
 }
Ejemplo n.º 6
0
 protected function attemptUpgrade(ConnectionInterface $conn, $data = '')
 {
     if ('' !== $data) {
         $conn->WebSocket->request->getBody()->write($data);
     }
     if (!$this->versioner->isVersionEnabled($conn->WebSocket->request)) {
         return $this->close($conn);
     }
     $conn->WebSocket->version = $this->versioner->getVersion($conn->WebSocket->request);
     try {
         $response = $conn->WebSocket->version->handshake($conn->WebSocket->request);
     } catch (\UnderflowException $e) {
         return;
     }
     if (null !== ($subHeader = $conn->WebSocket->request->getHeader('Sec-WebSocket-Protocol'))) {
         if ('' !== ($agreedSubProtocols = $this->getSubProtocolString($subHeader->normalize()))) {
             $response->setHeader('Sec-WebSocket-Protocol', $agreedSubProtocols);
         }
     }
     $response->setHeader('X-Powered-By', \Ratchet\VERSION);
     $conn->send((string) $response);
     if (101 != $response->getStatusCode()) {
         return $conn->close();
     }
     $upgraded = $conn->WebSocket->version->upgradeConnection($conn, $this->component);
     $this->connections->attach($conn, $upgraded);
     $upgraded->WebSocket->established = true;
     return $this->component->onOpen($upgraded);
 }
Ejemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function onOpen(ConnectionInterface $conn)
 {
     if (!isset($conn->Session) || !$conn->Session instanceof Session) {
         throw new \RuntimeException('Session is not defined. Make sure that SessionProvider is executed before FOSUserProvider.');
     }
     try {
         $token = unserialize($conn->Session->get('_security_main'));
         echo $token;
         $user = $token->getUser();
         $provider = $this->_container->get('fos_user.user_provider.username');
         $conn->User = $provider->refreshUser($user);
     } catch (Exception $ex) {
         $conn->User = null;
     }
     echo "ok";
     return $this->_app->onOpen($conn);
 }
Ejemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 public function onMessage(ConnectionInterface $from, $msg)
 {
     if (true === $from->WebSocket->established) {
         return $from->WebSocket->version->onMessage($this->connections[$from], $msg);
     }
     if (isset($from->WebSocket->request)) {
         $from->WebSocket->request->getBody()->write($msg);
     } else {
         try {
             if (null === ($request = $this->reqParser->onMessage($from, $msg))) {
                 return;
             }
         } catch (\OverflowException $oe) {
             return $this->close($from, 413);
         }
         if (!$this->versioner->isVersionEnabled($request)) {
             return $this->close($from);
         }
         $from->WebSocket->request = $request;
         $from->WebSocket->version = $this->versioner->getVersion($request);
     }
     try {
         $response = $from->WebSocket->version->handshake($from->WebSocket->request);
     } catch (\UnderflowException $e) {
         return;
     }
     if (null !== ($subHeader = $from->WebSocket->request->getHeader('Sec-WebSocket-Protocol'))) {
         if ('' !== ($agreedSubProtocols = $this->getSubProtocolString($subHeader->normalize()))) {
             $response->setHeader('Sec-WebSocket-Protocol', $agreedSubProtocols);
         }
     }
     $response->setHeader('X-Powered-By', \Ratchet\VERSION);
     $from->send((string) $response);
     if (101 != $response->getStatusCode()) {
         return $from->close();
     }
     $upgraded = $from->WebSocket->version->upgradeConnection($from, $this->_decorating);
     $this->connections->attach($from, $upgraded);
     $upgraded->WebSocket->established = true;
     return $this->_decorating->onOpen($upgraded);
 }
 /**
  * @param ConnectionInterface $connection
  *
  * @return mixed
  */
 public function onOpen(ConnectionInterface $connection)
 {
     $connection->PeriodicTimer = new ConnectionPeriodicTimer($connection, $this->loop);
     return $this->decorated->onOpen($connection);
 }
Ejemplo n.º 10
0
 /**
  * When a new connection is opened it will be passed to this method
  * @param  ConnectionInterface $conn The socket/connection that just connected to your application
  * @throws \Exception
  */
 public function onOpen(ConnectionInterface $conn)
 {
     $wrapper = new JsonConnection($conn);
     $this->connections->attach($conn, $wrapper);
     $this->wrapped->onOpen($wrapper);
 }