public function accept(Packet $packet)
 {
     if ($packet->getPacketType() !== Packet::TYPE_UNSUBACK) {
         return false;
     }
     /* @var UnsubscribeResponsePacket $packet */
     return $packet->getIdentifier() === $this->identifier;
 }
示例#2
0
 public function accept(Packet $packet)
 {
     if ($this->message->getQosLevel() !== 2 || $packet->getPacketType() !== Packet::TYPE_PUBREL) {
         return false;
     }
     /* @var PublishReleasePacket $packet */
     return $packet->getIdentifier() === $this->identifier;
 }
示例#3
0
 public function next(Packet $packet)
 {
     /** @var ConnectResponsePacket $packet */
     if ($packet->isSuccess()) {
         $this->succeed($this->connection);
     } else {
         $this->fail($packet->getErrorName());
     }
 }
示例#4
0
 public function next(Packet $packet)
 {
     $packetType = $packet->getPacketType();
     if ($packetType === Packet::TYPE_PUBACK || $packetType === Packet::TYPE_PUBCOMP) {
         $this->succeed($this->message);
     } elseif ($packetType === Packet::TYPE_PUBREC) {
         $this->receivedPubRec = true;
         $response = new PublishReleasePacket();
         $response->setIdentifier($this->identifier);
         return $response;
     }
 }
 public function next(Packet $packet)
 {
     /* @var SubscribeResponsePacket $packet */
     $returnCodes = $packet->getReturnCodes();
     if (count($returnCodes) !== count($this->subscriptions)) {
         throw new \LogicException(sprintf('SUBACK: Expected %d return codes but got %d.', count($this->subscriptions), count($returnCodes)));
     }
     foreach ($returnCodes as $index => $code) {
         if ($packet->isError($code)) {
             $this->fail(sprintf('Failed to subscribe to "%s".', $this->subscriptions[$index]->getFilter()));
             return;
         }
     }
     $this->succeed($this->subscriptions[0]);
 }
 /**
  * Handles an incoming packet.
  *
  * @param Packet $packet
  */
 private function handlePacket(Packet $packet)
 {
     switch ($packet->getPacketType()) {
         case Packet::TYPE_PUBLISH:
             /* @var PublishRequestPacket $packet */
             $message = new DefaultMessage($packet->getTopic(), $packet->getPayload(), $packet->getQosLevel(), $packet->isRetained(), $packet->isDuplicate());
             $this->startFlow(new IncomingPublishFlow($message, $packet->getIdentifier()));
             break;
         case Packet::TYPE_CONNACK:
         case Packet::TYPE_PINGRESP:
         case Packet::TYPE_SUBACK:
         case Packet::TYPE_UNSUBACK:
         case Packet::TYPE_PUBREL:
         case Packet::TYPE_PUBACK:
         case Packet::TYPE_PUBREC:
         case Packet::TYPE_PUBCOMP:
             $flowFound = false;
             foreach ($this->receivingFlows as $index => $flow) {
                 if ($flow->accept($packet)) {
                     $flowFound = true;
                     unset($this->receivingFlows[$index]);
                     $this->continueFlow($flow, $packet);
                     break;
                 }
             }
             if (!$flowFound) {
                 $this->emitWarning(new \LogicException(sprintf('Received unexpected packet of type %d.', $packet->getPacketType())));
             }
             break;
         default:
             $this->emitWarning(new \LogicException(sprintf('Cannot handle packet of type %d.', $packet->getPacketType())));
     }
 }
示例#7
0
 public function accept(Packet $packet)
 {
     return $packet->getPacketType() === Packet::TYPE_PINGRESP;
 }