コード例 #1
0
ファイル: Connection.php プロジェクト: koolkode/async-http
 /**
  * Handle a WebSocket control frame.
  * 
  * Sending pong frames might happen at anytime between sending continuation frames.
  */
 protected function handleControlFrame(Frame $frame) : \Generator
 {
     switch ($frame->opcode) {
         case Frame::CONNECTION_CLOSE:
             return false;
         case Frame::PING:
             (yield $this->writer->writeFrame(new Frame(Frame::PONG, $frame->data), 1000));
             break;
         case Frame::PONG:
             if (isset($this->pings[$frame->data])) {
                 try {
                     $this->pings[$frame->data]->resolve(true);
                 } finally {
                     unset($this->pings[$frame->data]);
                 }
             }
             break;
     }
     return true;
 }