Exemple #1
0
 /**
  * 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;
 }
 /**
  * Create a new compression-enabled message writer.
  * 
  * @param SocketStream $socket
  * @param bool $client
  * @param PerMessageDeflate $deflate
  */
 public function __construct(SocketStream $socket, bool $client, PerMessageDeflate $deflate)
 {
     parent::__construct($socket, $client);
     $this->deflate = $deflate;
 }