Example #1
0
 /**
  * Handle a complete payload received from the client
  *
  * Public because called from our PayloadHandler
  *
  * @param string $payload
  */
 public function handlePayload(Payload $payload)
 {
     $app = $this->getClientApplication();
     $this->logger->debug('Handling payload: ' . $payload->getPayload());
     switch ($type = $payload->getType()) {
         case Protocol::TYPE_TEXT:
             if (method_exists($app, 'onData')) {
                 $app->onData($payload, $this);
             }
             return;
         case Protocol::TYPE_BINARY:
             if (method_exists($app, 'onBinaryData')) {
                 $app->onBinaryData($payload, $this);
             } else {
                 $this->close(1003);
             }
             break;
         case Protocol::TYPE_PING:
             $this->logger->info('Ping received');
             $this->send($payload->getPayload(), Protocol::TYPE_PONG);
             $this->logger->debug('Pong!');
             break;
             /**
              * A Pong frame MAY be sent unsolicited.  This serves as a
              * unidirectional heartbeat.  A response to an unsolicited Pong
              * frame is not expected.
              */
         /**
          * A Pong frame MAY be sent unsolicited.  This serves as a
          * unidirectional heartbeat.  A response to an unsolicited Pong
          * frame is not expected.
          */
         case Protocol::TYPE_PONG:
             $this->logger->info('Received unsolicited pong');
             break;
         case Protocol::TYPE_CLOSE:
             $this->logger->info('Close frame received');
             $this->close();
             $this->logger->info('Disconnected');
             break;
         default:
             throw new ConnectionException('Unhandled payload type');
     }
 }