Example #1
0
 public static function handleRequest(Request $request)
 {
     $handshakeResult = Handshake::initialize($request);
     if ($handshakeResult === Handshake::PROTOCOL_HTMLFILE) {
         return;
     }
     if ($handshakeResult instanceof Response) {
         $request->getConnection()->write($handshakeResult, true);
         return;
     }
 }
Example #2
0
 protected function initEvent($group)
 {
     $dispatcher = Event\EventDispatcher::getDispatcher();
     $dispatcher->addListener("socket.receive", function (Event\MessageEvent $messageEvent) {
         $message = $messageEvent->getMessage();
         $frame = $this->websocket->onMessage($message);
         if (!$frame instanceof WebSocket\Frame) {
             return;
         }
         Handshake::processProtocol($frame->getData(), $this->getConnection());
     }, $group);
     $dispatcher->addListener("server.emit", function (Event\MessageEvent $messageEvent) {
         $endpoint = $this->getRequest()->getSession()->get('endpoint', $messageEvent->getEndpoint());
         $message = $messageEvent->getMessage();
         $this->sendData(ProtocolBuilder::Event(array('name' => $message['event'], 'args' => array($message['message'])), $endpoint));
     }, $group);
 }
Example #3
0
 protected function processPOSTMethod()
 {
     Handshake::processProtocol($this->parseClientEmitData(), $this->getConnection());
     $response = $this->setResponseHeaders(new Response('1'));
     $this->getConnection()->write($response);
 }