mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
parent
c5efdf5ae3
commit
020eaef5ba
@ -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 = {};
|
||||
|
Loading…
Reference in New Issue
Block a user