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

Ensure mqtt message handlers are tidied up properly on partial deploy

This commit is contained in:
Nick O'Leary 2019-03-29 10:30:11 +00:00
parent 8ac3899ddc
commit 63829b6382
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -315,7 +315,7 @@ module.exports = function(RED) {
}
};
this.unsubscribe = function (topic, ref) {
this.unsubscribe = function (topic, ref, removed) {
ref = ref||0;
var sub = node.subscriptions[topic];
if (sub) {
@ -323,6 +323,7 @@ module.exports = function(RED) {
node.client.removeListener('message',sub[ref].handler);
delete sub[ref];
}
if (removed) {
if (Object.keys(sub).length === 0) {
delete node.subscriptions[topic];
if (node.connected) {
@ -330,6 +331,7 @@ module.exports = function(RED) {
}
}
}
}
};
this.publish = function (msg) {
@ -430,10 +432,7 @@ module.exports = function(RED) {
}
this.on('close', function(removed, done) {
if (node.brokerConn) {
if (removed) {
// This node has been removed so remove any subscriptions
node.brokerConn.unsubscribe(node.topic,node.id);
}
node.brokerConn.unsubscribe(node.topic,node.id, removed);
node.brokerConn.deregister(node,done);
}
});