automatically use resposeTopic if topic is empty

This commit is contained in:
Steve-Mcl 2020-12-07 09:43:52 +00:00
parent 6917919f35
commit 27550f2d4b
1 changed files with 8 additions and 3 deletions

View File

@ -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);