Exemplo n.º 1
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);
 }
Exemplo n.º 2
0
 protected function initEvent()
 {
     $dispatcher = Event\EventDispatcher::getDispatcher();
     $dispatcher->addListener("connect", function () {
         $endpoint = $this->getRequest()->getSession()->get('endpoint');
         $this->writeChunkEnd(ProtocolBuilder::Connect($endpoint));
     }, array($this->connection->getSessionId()));
     $dispatcher->addListener("server.emit", function (Event\MessageEvent $messageEvent) {
         $message = $messageEvent->getMessage();
         if ($this->connection->isConnectionClose()) {
             $this->connection->queuePendingEmitEvent("server.emit", $message);
             return;
         }
         $endpoint = $this->getRequest()->getSession()->get('endpoint', $messageEvent->getEndpoint());
         $this->writeChunkEnd(ProtocolBuilder::Event(array('name' => $message['event'], 'args' => array($message['message'])), $endpoint));
     }, array($this->connection->getSessionId(), $this->getRequest()->getSession()->get('endpoint')));
 }