1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Only unsub mqtt node that is being removed

This commit is contained in:
Nick O'Leary 2018-11-08 17:03:41 +01:00
parent 6a6d13b075
commit 073f38c68c
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

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