Skip to content

Commit

Permalink
feat(mqtt): Ignore received retained message to work around common us…
Browse files Browse the repository at this point in the history
…er errors
  • Loading branch information
Hypfer committed Jun 20, 2021
1 parent 32a12cf commit 26d8a4c
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion backend/lib/mqtt/MqttController.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,22 @@ class MqttController {
});
});

this.client.on("message", (topic, message) => {
this.client.on("message", (topic, message, packet) => {
if (!Object.prototype.hasOwnProperty.call(this.subscriptions, topic)) {
return;
}
const msg = message.toString();

//@ts-ignore
if (packet?.retain === true) {
Logger.warn("Received a retained MQTT message. This is almost certainly an error. Discarding.", {
topic: topic,
message: msg
});

return;
}

this.subscriptions[topic](msg).then();
});

Expand Down

0 comments on commit 26d8a4c

Please sign in to comment.