mirror of
https://github.com/node-red/node-red.git
synced 2025-12-26 23:26:46 +01:00
Ensure MQTT nodes unsubscribe before disconnect
Fixes #609 Needed for partial deployment - the nodes assumed the connection would always be closed when a deploy occurs.
This commit is contained in:
@@ -53,14 +53,18 @@ module.exports = function(RED) {
|
||||
msg._topic = topic;
|
||||
}
|
||||
node.send(msg);
|
||||
});
|
||||
}, this.id);
|
||||
this.client.on("connectionlost",function() {
|
||||
node.status({fill:"red",shape:"ring",text:"disconnected"});
|
||||
});
|
||||
this.client.on("connect",function() {
|
||||
node.status({fill:"green",shape:"dot",text:"connected"});
|
||||
});
|
||||
this.client.connect();
|
||||
if (this.client.isConnected()) {
|
||||
node.status({fill:"green",shape:"dot",text:"connected"});
|
||||
} else {
|
||||
this.client.connect();
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.error("topic not defined");
|
||||
@@ -70,6 +74,7 @@ module.exports = function(RED) {
|
||||
}
|
||||
this.on('close', function() {
|
||||
if (this.client) {
|
||||
this.client.unsubscribe(this.topic,this.id);
|
||||
this.client.disconnect();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user