Skip to content

Commit

Permalink
Fix: Send PUBREL in response to PUBREC (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
Namoshek authored Aug 19, 2020
1 parent 289fa18 commit 79b3b99
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
<description>php-mqtt Code Style Standard</description>

<rule ref="PSR1"/>
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="PSR2">
<exclude name="PSR2.Methods.MethodDeclaration.AbstractAfterVisibility"/>
<exclude name="Squiz.ControlStructures.ControlSignature.SpaceAfterCloseParenthesis"/>
Expand Down
19 changes: 19 additions & 0 deletions src/MQTTClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,8 @@ protected function handlePublishReceipt(string $buffer): void
'The MQTT broker sent a receipt for a publish that has not been pending anymore.'
);
}

$this->sendPublishRelease($messageId);
}

/**
Expand Down Expand Up @@ -1272,6 +1274,23 @@ protected function sendPublishReceived(int $messageId): void
$this->writeToSocket(chr(0x50) . chr(0x02) . $this->encodeMessageId($messageId));
}

/**
* Sends a publish release message for the given message identifier.
*
* @param int $messageId
* @return void
* @throws DataTransferException
*/
protected function sendPublishRelease(int $messageId): void
{
$this->logger->debug('Sending publish release message to an MQTT broker.', [
'broker' => sprintf('%s:%s', $this->host, $this->port),
'message_id' => $messageId,
]);

$this->writeToSocket(chr(0x62) . chr(0x02) . $this->encodeMessageId($messageId));
}

/**
* Sends a publish complete message for the given message identifier.
*
Expand Down

0 comments on commit 79b3b99

Please sign in to comment.