Example #1
0
 public function __construct(Request $request)
 {
     $uniqueId = sha1(microtime() . rand(), true);
     $this->setRequest($request);
     $this->setConnection($request->getConnection());
     $this->websocket = new WebSocket\WebSocket();
     if (!($handshakeResponse = $this->websocket->getHandshakeReponse($request))) {
         $this->getConnection()->write(new Response('bad protocol', 400), true);
         return;
     }
     $this->getConnection()->write($handshakeResponse);
     $this->sendData(ProtocolBuilder::Connect());
     $this->initEvent(array($this->connection->getSessionId(), $uniqueId));
     $this->setHeartbeatTimeout();
     $dispatcher = Event\EventDispatcher::getDispatcher();
     $dispatcher->addListener('connect', function () use($dispatcher, $uniqueId) {
         $endpoint = $this->getRequest()->getSession()->get('endpoint');
         $dispatcher->removeGroupListener($uniqueId);
         $this->initEvent(array($this->connection->getSessionId(), $endpoint));
         $this->sendData(ProtocolBuilder::Connect($endpoint));
     }, array($this->getConnection()->getSessionId()));
 }
Example #2
0
 protected function init()
 {
     $response = $this->setResponseHeaders(new Response($this->generateResponseData(ProtocolBuilder::Connect())));
     $this->getConnection()->write($response, true);
 }