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

Merge pull request #3552 from Steve-Mcl/fix-mqtt-status

Fix incorrect MQTT status
This commit is contained in:
Stephen McLaughlin 2022-04-26 23:57:55 +01:00 committed by GitHub
commit f717eb7388
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -362,7 +362,7 @@ module.exports = function(RED) {
node.brokerConn.connect(function () {
done();
});
})
}, true)
} else {
// Without force flag, we will refuse to cycle an active connection
done(new Error(RED._('mqtt.errors.invalid-action-alreadyconnected')));
@ -750,32 +750,35 @@ module.exports = function(RED) {
}
}
};
node.disconnect = function (callback) {
const _callback = function (resetNodeConnectedState) {
node.disconnect = function (callback, force) {
const _callback = function (resetNodeConnectedState, _force) {
setStatusDisconnected(node, true);
if(resetNodeConnectedState) {
if(resetNodeConnectedState || _force) {
node.client.removeAllListeners();
node.closing = true;
node.connecting = false;
node.connected = false;
}
callback && typeof callback == "function" && callback();
};
if(node.closing) {
return _callback(false);
return _callback(false, force);
}
var endCallBack = function endCallBack() {
}
if(node.connected && node.closeMessage) {
node.publish(node.closeMessage, function (err) {
node.client.end(endCallBack);
_callback(true);
_callback(true, force);
});
} else if(node.connected) {
node.client.end(endCallBack);
_callback(true);
_callback(true, force);
} else if(node.connecting) {
node.client.end();
_callback(true, true);
} else {
_callback(false);
_callback(false, force);
}
}
node.subscriptionIds = {};