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

Fix incorrect MQTT status

fixes #3550
This commit is contained in:
Stephen McLaughlin 2022-04-26 16:12:54 +01:00 committed by GitHub
parent c5efdf5ae3
commit 020eaef5ba
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 () { node.brokerConn.connect(function () {
done(); done();
}); });
}) }, true)
} else { } else {
// Without force flag, we will refuse to cycle an active connection // Without force flag, we will refuse to cycle an active connection
done(new Error(RED._('mqtt.errors.invalid-action-alreadyconnected'))); done(new Error(RED._('mqtt.errors.invalid-action-alreadyconnected')));
@ -750,32 +750,35 @@ module.exports = function(RED) {
} }
} }
}; };
node.disconnect = function (callback) { node.disconnect = function (callback, force) {
const _callback = function (resetNodeConnectedState) { const _callback = function (resetNodeConnectedState, _force) {
setStatusDisconnected(node, true); setStatusDisconnected(node, true);
if(resetNodeConnectedState) { if(resetNodeConnectedState || _force) {
node.client.removeAllListeners();
node.closing = true; node.closing = true;
node.connecting = false; node.connecting = false;
node.connected = false; node.connected = false;
} }
callback && typeof callback == "function" && callback(); callback && typeof callback == "function" && callback();
}; };
if(node.closing) { if(node.closing) {
return _callback(false); return _callback(false, force);
} }
var endCallBack = function endCallBack() { var endCallBack = function endCallBack() {
} }
if(node.connected && node.closeMessage) { if(node.connected && node.closeMessage) {
node.publish(node.closeMessage, function (err) { node.publish(node.closeMessage, function (err) {
node.client.end(endCallBack); node.client.end(endCallBack);
_callback(true); _callback(true, force);
}); });
} else if(node.connected) { } else if(node.connected) {
node.client.end(endCallBack); node.client.end(endCallBack);
_callback(true); _callback(true, force);
} else if(node.connecting) {
node.client.end();
_callback(true, true);
} else { } else {
_callback(false); _callback(false, force);
} }
} }
node.subscriptionIds = {}; node.subscriptionIds = {};