mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
fix single subscription mqtt node status
This commit is contained in:
parent
14e74afb07
commit
5bb66ed7d4
@ -366,6 +366,16 @@ module.exports = function(RED) {
|
||||
}
|
||||
}
|
||||
|
||||
function updateStatus(node, allNodes) {
|
||||
let setStatus = setStatusDisconnected
|
||||
if(node.connecting) {
|
||||
setStatus = setStatusConnecting
|
||||
} else if(node.connected) {
|
||||
setStatus = setStatusConnected
|
||||
}
|
||||
setStatus(node, allNodes)
|
||||
}
|
||||
|
||||
function setStatusDisconnected(node, allNodes) {
|
||||
if(allNodes) {
|
||||
for (var id in node.users) {
|
||||
@ -697,13 +707,17 @@ module.exports = function(RED) {
|
||||
if (Object.keys(node.users).length === 1) {
|
||||
if(node.autoConnect) {
|
||||
node.connect();
|
||||
//update nodes status
|
||||
setTimeout(function() {
|
||||
updateStatus(node, true)
|
||||
}, 1)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
node.deregister = function(mqttNode,done) {
|
||||
node.deregister = function(mqttNode, done, autoDisconnect) {
|
||||
delete node.users[mqttNode.id];
|
||||
if (!node.closing && node.connected && Object.keys(node.users).length === 0) {
|
||||
if (autoDisconnect && !node.closing && node.connected && Object.keys(node.users).length === 0) {
|
||||
node.disconnect();
|
||||
}
|
||||
done();
|
||||
@ -1220,7 +1234,7 @@ module.exports = function(RED) {
|
||||
} else {
|
||||
node.brokerConn.unsubscribe(node.topic,node.id, removed);
|
||||
}
|
||||
node.brokerConn.deregister(node, done);
|
||||
node.brokerConn.deregister(node, done, removed);
|
||||
node.brokerConn = null;
|
||||
} else {
|
||||
done();
|
||||
@ -1283,9 +1297,9 @@ module.exports = function(RED) {
|
||||
node.status({fill:"green",shape:"dot",text:"node-red:common.status.connected"});
|
||||
}
|
||||
node.brokerConn.register(node);
|
||||
node.on('close', function(done) {
|
||||
node.on('close', function(removed, done) {
|
||||
if (node.brokerConn) {
|
||||
node.brokerConn.deregister(node,done);
|
||||
node.brokerConn.deregister(node, done, removed)
|
||||
node.brokerConn = null;
|
||||
} else {
|
||||
done();
|
||||
|
Loading…
Reference in New Issue
Block a user