From 080e2f25896906ddb55c006075aa02f745b98af7 Mon Sep 17 00:00:00 2001 From: Steve-Mcl Date: Thu, 25 Feb 2021 19:58:59 +0000 Subject: [PATCH] mqtt v5 fixes - copy/paste issues with willMsg - ensure helper func is ran for lwt messages --- .../@node-red/nodes/core/network/10-mqtt.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 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 c9d0c8246..db4d300fe 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 @@ -188,7 +188,7 @@ module.exports = function(RED) { setStrProp(n.birthMsg, this.birthMessage, "contentType"); if(n.birthMsg.userProps && /^ *{/.test(n.birthMsg.userProps)) { try { - this.birthMessage.userProperties = JSON.parse(n.birthMsg.userProps) + setUserProperties(JSON.parse(n.birthMsg.userProps), this.birthMessage); } catch(err) {} } n.birthMsg.responseTopic = n.birthMsg.respTopic; @@ -196,7 +196,7 @@ module.exports = function(RED) { n.birthMsg.correlationData = n.birthMsg.correl; setBufferProp(n.birthMsg, this.birthMessage, "correlationData"); n.birthMsg.messageExpiryInterval = n.birthMsg.expiry - setIntProp(n.willMsg,this.birthMessage, "messageExpiryInterval") + setIntProp(n.birthMsg,this.birthMessage, "messageExpiryInterval") } } @@ -212,7 +212,7 @@ module.exports = function(RED) { setStrProp(n.closeMsg, this.closeMessage, "contentType"); if(n.closeMsg.userProps && /^ *{/.test(n.closeMsg.userProps)) { try { - this.closeMessage.userProperties = JSON.parse(n.closeMsg.userProps) + setUserProperties(JSON.parse(n.closeMsg.userProps), this.closeMessage); } catch(err) {} } n.closeMsg.responseTopic = n.closeMsg.respTopic; @@ -220,7 +220,7 @@ module.exports = function(RED) { n.closeMsg.correlationData = n.closeMsg.correl; setBufferProp(n.closeMsg, this.closeMessage, "correlationData"); n.closeMsg.messageExpiryInterval = n.closeMsg.expiry - setIntProp(n.willMsg,this.closeMessage, "messageExpiryInterval") + setIntProp(n.birthMsg,this.closeMessage, "messageExpiryInterval") } } @@ -365,7 +365,7 @@ module.exports = function(RED) { setStrProp(n.willMsg, this.options.will.properties, "contentType"); if(n.willMsg.userProps && /^ *{/.test(n.willMsg.userProps)) { try { - this.options.will.properties.userProperties = JSON.parse(n.willMsg.userProps) + setUserProperties(JSON.parse(n.willMsg.userProps), this.options.will.properties); } catch(err) {} } n.willMsg.responseTopic = n.willMsg.respTopic; @@ -612,9 +612,6 @@ module.exports = function(RED) { setBufferProp(msg, options.properties, "correlationData"); setStrProp(msg, options.properties, "contentType"); setIntProp(msg, options.properties, "messageExpiryInterval", 0); - if (msg.userProperties) { - options.properties.userProperties = msg.userProperties; - } setUserProperties(msg.userProperties, options.properties); setIntProp(msg, options.properties, "topicAlias", 1, node.serverProperties.topicAliasMaximum || 0); setBoolProp(msg, options.properties, "payloadFormatIndicator"); @@ -774,7 +771,8 @@ module.exports = function(RED) { this.messageExpiryInterval = n.expiry; //https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901112 try { if (/^ *{/.test(n.userProps)) { - this.userProperties = JSON.parse(n.userProps);//https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901116 + //setup this.userProperties + setUserProperties(JSON.parse(n.userProps), this);//https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901116 } } catch(err) {} // this.topicAlias = n.topicAlias; //https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901113