mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge pull request #3992 from node-red/fix-mqtt-reconnect
Fix mqtt nodes not reconnecting on modified-flows deploy
This commit is contained in:
commit
e0d71abdc6
@ -295,7 +295,7 @@ module.exports = function(RED) {
|
|||||||
/* mute error - it simply isnt JSON, just leave payload as a string */
|
/* mute error - it simply isnt JSON, just leave payload as a string */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} //else {
|
} //else {
|
||||||
//leave as buffer
|
//leave as buffer
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
@ -357,7 +357,7 @@ module.exports = function(RED) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
done();
|
done();
|
||||||
}
|
}
|
||||||
@ -718,9 +718,10 @@ module.exports = function(RED) {
|
|||||||
node.deregister = function(mqttNode, done, autoDisconnect) {
|
node.deregister = function(mqttNode, done, autoDisconnect) {
|
||||||
delete node.users[mqttNode.id];
|
delete node.users[mqttNode.id];
|
||||||
if (autoDisconnect && !node.closing && node.connected && Object.keys(node.users).length === 0) {
|
if (autoDisconnect && !node.closing && node.connected && Object.keys(node.users).length === 0) {
|
||||||
node.disconnect();
|
node.disconnect(done);
|
||||||
|
} else {
|
||||||
|
done();
|
||||||
}
|
}
|
||||||
done();
|
|
||||||
};
|
};
|
||||||
node.canConnect = function() {
|
node.canConnect = function() {
|
||||||
return !node.connected && !node.connecting;
|
return !node.connected && !node.connecting;
|
||||||
@ -854,7 +855,7 @@ module.exports = function(RED) {
|
|||||||
let waitEnd = (client, ms) => {
|
let waitEnd = (client, ms) => {
|
||||||
return new Promise( (resolve, reject) => {
|
return new Promise( (resolve, reject) => {
|
||||||
node.closing = true;
|
node.closing = true;
|
||||||
if(!client) {
|
if(!client) {
|
||||||
resolve();
|
resolve();
|
||||||
} else {
|
} else {
|
||||||
const t = setTimeout(() => {
|
const t = setTimeout(() => {
|
||||||
@ -1033,7 +1034,7 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add event handlers to the MQTT.js client and track them so that
|
* Add event handlers to the MQTT.js client and track them so that
|
||||||
* we do not remove any handlers that the MQTT client uses internally.
|
* we do not remove any handlers that the MQTT client uses internally.
|
||||||
* Use {@link node._clientRemoveListeners `node._clientRemoveListeners`} to remove handlers
|
* Use {@link node._clientRemoveListeners `node._clientRemoveListeners`} to remove handlers
|
||||||
* @param {string} event The name of the event
|
* @param {string} event The name of the event
|
||||||
* @param {function} handler The handler for this event
|
* @param {function} handler The handler for this event
|
||||||
@ -1041,11 +1042,11 @@ module.exports = function(RED) {
|
|||||||
node._clientOn = function(event, handler) {
|
node._clientOn = function(event, handler) {
|
||||||
node.clientListeners.push({event, handler})
|
node.clientListeners.push({event, handler})
|
||||||
node.client.on(event, handler)
|
node.client.on(event, handler)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove event handlers from the MQTT.js client & only the events
|
* Remove event handlers from the MQTT.js client & only the events
|
||||||
* that we attached in {@link node._clientOn `node._clientOn`}.
|
* that we attached in {@link node._clientOn `node._clientOn`}.
|
||||||
* * If `event` is omitted, then all events matching `handler` are removed
|
* * If `event` is omitted, then all events matching `handler` are removed
|
||||||
* * If `handler` is omitted, then all events named `event` are removed
|
* * If `handler` is omitted, then all events named `event` are removed
|
||||||
* * If both parameters are omitted, then all events are removed
|
* * If both parameters are omitted, then all events are removed
|
||||||
|
Loading…
Reference in New Issue
Block a user