Exemple #1
0
 /**
  * Extends listen()
  *
  * @param string  $url       Web Socket URL
  * @param array   $sockConf  Web Socket Configuration
  * @param closure $callback  Anonymous method to return frames to
  *
  * @return void
  */
 private function _listen($url, $sockConf, $callback)
 {
     // connecting to websocket server
     $client = new \Devristo\Phpws\Client\WebSocket($url . '&sid=' . $sockConf[1], $this->_loop, Logger::getInstance(), array('http' => array('header' => 'Cookie:' . $sockConf[0])));
     // request
     $client->on("request", function ($headers) {
         // object created
         Logger::notice("[SOCKET] Request object created!");
     });
     // handshake
     $client->on("handshake", function () {
         // handshake made with server
         Logger::notice("[SOCKET] Handshake received!");
     });
     // connect
     $client->on("connect", function () use($client) {
         // connected to websocket
         Logger::notice("[SOCKET] Connected to Websocket!");
         // request connection
         $client->send('2probe');
     });
     // message
     $client->on("message", function ($message) use($client, $url, $sockConf, $callback) {
         // store data in frame
         $frame = $message->getData();
         // if socket has died out
         $this->handleFrame($frame, $client, $callback);
     });
     // start client listener
     $client->open();
     // start looping requests
     $this->_loop->run();
 }