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:
Nick O'Leary
2015-04-09 20:10:34 +01:00
parent 0e926c566b
commit f48ee01a03
3 changed files with 47 additions and 13 deletions

View File

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