Fix frontend api messages pollution (#4326)

This commit is contained in:
John Doe authored and GitHub committed 2020-09-10 20:54:03 +08:00
1 parent c29cc784ba
commit 9cabe1e23a
2 files changed
+15 -12

No files matched your search

+11 -9
View File
@@ -98,16 +98,18 @@ class Frontend extends Extension {
onMQTTPublishedMessage(data) {
let {topic, payload, options} = data;
// Send topic without base_topic
topic = topic.substring(this.mqttBaseTopic.length + 1);
payload = utils.parseJSON(payload, payload);
if (options.retain) {
this.retainedMessages.set(topic, payload);
}
if (topic.startsWith(`${this.mqttBaseTopic}/`)) {
// Send topic without base_topic
topic = topic.substring(this.mqttBaseTopic.length + 1);
payload = utils.parseJSON(payload, payload);
if (options.retain) {
this.retainedMessages.set(topic, payload);
}
for (const client of this.wss.clients) {
if (client.readyState === WebSocket.OPEN) {
client.send(stringify({topic, payload}));
for (const client of this.wss.clients) {
if (client.readyState === WebSocket.OPEN) {
client.send(stringify({topic, payload}));
}
}
}
}