From 27550f2d4bf3090d3b160a446d82cc0cba339f54 Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Mon, 7 Dec 2020 09:43:52 +0000 Subject: [PATCH] automatically use resposeTopic if topic is empty --- .../@node-red/nodes/core/network/10-mqtt.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js index bcc458d52..4f5655666 100644 --- a/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js +++ b/packages/node_modules/@node-red/nodes/core/network/10-mqtt.js @@ -758,9 +758,14 @@ module.exports = function(RED) { } if ( msg.hasOwnProperty("payload")) { let topicOK = msg.hasOwnProperty("topic") && (typeof msg.topic === "string") && (msg.topic !== ""); - if(!topicOK && v5 && msg.topicAlias && node.brokerConn.serverProperties.topicAliasMaximum) { - topicOK = typeof msg.topicAlias === "number" && msg.topicAlias >= 0 && node.brokerConn.serverProperties.topicAliasMaximum >= msg.topicAlias - msg.topic = "";//must be empty string? + if (!topicOK && v5) { + if (msg.hasOwnProperty("topicAlias") && typeof msg.topicAlias === "number" && msg.topicAlias >= 0 && node.brokerConn.serverProperties.topicAliasMaximum && node.brokerConn.serverProperties.topicAliasMaximum >= msg.topicAlias) { + topicOK = true; + msg.topic = ""; //must be empty string + } else if (msg.hasOwnProperty("responseTopic") && (typeof msg.responseTopic === "string") && (msg.responseTopic !== "")) { + topicOK = true; + msg.topic = msg.responseTopic; + } } if (topicOK) { // topic must exist debug(`MQTTOutNode:${node.id}: sending msg to ${msg.topic}`, msg);