Skip to content

Commit

Permalink
- Added onMessage event with comparation
Browse files Browse the repository at this point in the history
  • Loading branch information
akadlec committed Nov 8, 2019
1 parent c6d4d2d commit 354fad7
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/IPub/MQTTClient/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ final class Client implements IClient
*/
private $timer = [];

/**
* @var Mqtt\Message|NULL
*/
private $lastMessage = NULL;

/**
* @param EventLoop\LoopInterface $eventLoop
* @param Configuration $configuration
Expand Down Expand Up @@ -811,7 +816,22 @@ private function finishFlow(Flow\Envelope $flow) : void
break;

case 'message':
$this->onMessage($flow->getResult(), $this);
/** @var Mqtt\Message $message */
$message = $flow->getResult();

if ($this->lastMessage === NULL) {
$this->lastMessage = $flow->getResult();

} elseif (
$this->lastMessage->getTopic() === $message->getTopic()
&& $this->lastMessage->getPayload() === $message->getPayload()
) {
break;
}

$this->lastMessage = $message;

$this->onMessage($message, $this);
break;
}
}
Expand Down

0 comments on commit 354fad7

Please sign in to comment.