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:
parent
8ac3899ddc
commit
63829b6382
@ -315,7 +315,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.unsubscribe = function (topic, ref) {
|
this.unsubscribe = function (topic, ref, removed) {
|
||||||
ref = ref||0;
|
ref = ref||0;
|
||||||
var sub = node.subscriptions[topic];
|
var sub = node.subscriptions[topic];
|
||||||
if (sub) {
|
if (sub) {
|
||||||
@ -323,10 +323,12 @@ module.exports = function(RED) {
|
|||||||
node.client.removeListener('message',sub[ref].handler);
|
node.client.removeListener('message',sub[ref].handler);
|
||||||
delete sub[ref];
|
delete sub[ref];
|
||||||
}
|
}
|
||||||
if (Object.keys(sub).length === 0) {
|
if (removed) {
|
||||||
delete node.subscriptions[topic];
|
if (Object.keys(sub).length === 0) {
|
||||||
if (node.connected) {
|
delete node.subscriptions[topic];
|
||||||
node.client.unsubscribe(topic);
|
if (node.connected) {
|
||||||
|
node.client.unsubscribe(topic);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -430,10 +432,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
this.on('close', function(removed, done) {
|
this.on('close', function(removed, done) {
|
||||||
if (node.brokerConn) {
|
if (node.brokerConn) {
|
||||||
if (removed) {
|
node.brokerConn.unsubscribe(node.topic,node.id, removed);
|
||||||
// This node has been removed so remove any subscriptions
|
|
||||||
node.brokerConn.unsubscribe(node.topic,node.id);
|
|
||||||
}
|
|
||||||
node.brokerConn.deregister(node,done);
|
node.brokerConn.deregister(node,done);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user