diff --git a/packages/node_modules/@node-red/nodes/core/io/10-mqtt.js b/packages/node_modules/@node-red/nodes/core/io/10-mqtt.js index ff152c7b8..f50195844 100644 --- a/packages/node_modules/@node-red/nodes/core/io/10-mqtt.js +++ b/packages/node_modules/@node-red/nodes/core/io/10-mqtt.js @@ -28,7 +28,7 @@ module.exports = function(RED) { } /* The following allows shared subscriptions (as in MQTT v5) http://docs.oasis-open.org/mqtt/mqtt/v5.0/cs02/mqtt-v5.0-cs02.html#_Toc514345522 - + 4.8.2 describes shares like: $share/{ShareName}/{filter} $share is a literal string that marks the Topic Filter as being a Shared Subscription Topic Filter. @@ -37,7 +37,7 @@ module.exports = function(RED) { */ else if(ts.startsWith("$share")){ ts = ts.replace(/^\$share\/[^#+/]+\/(.*)/g,"$1"); - + } var re = new RegExp("^"+ts.replace(/([\[\]\?\(\)\\\\$\^\*\.|])/g,"\\$1").replace(/\+/g,"[^/]+").replace(/\/#$/,"(\/.*)?")+"$"); return re.test(t); @@ -81,7 +81,7 @@ module.exports = function(RED) { payload: n.closePayload || "", qos: Number(n.closeQos||0), retain: n.closeRetain=="true"|| n.closeRetain===true - }; + }; } if (this.credentials) { @@ -421,9 +421,12 @@ module.exports = function(RED) { else { this.error(RED._("mqtt.errors.not-defined")); } - this.on('close', function(done) { + this.on('close', function(removed, done) { if (node.brokerConn) { - node.brokerConn.unsubscribe(node.topic,node.id); + if (removed) { + // This node has been removed so remove any subscriptions + node.brokerConn.unsubscribe(node.topic,node.id); + } node.brokerConn.deregister(node,done); } }); @@ -476,4 +479,4 @@ module.exports = function(RED) { } } RED.nodes.registerType("mqtt out",MQTTOutNode); -}; \ No newline at end of file +};