mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
make sure MQTT client closes if redeploy during reconnect
to close #1193 Thanks @tedhuang for the excellent problem determination
This commit is contained in:
parent
15cd93c30f
commit
0c1c710afe
@ -35,7 +35,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/x-red" data-help-name="mqtt in">
|
<script type="text/x-red" data-help-name="mqtt in">
|
||||||
<p>Connects to a broker and subscribes to the specified topic.</p>
|
<p>Connects to a MQTT broker and subscribes to the specified topic.</p>
|
||||||
<p>Outputs a message with the properties:</p>
|
<p>Outputs a message with the properties:</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><code>msg.topic</code></li>
|
<li><code>msg.topic</code></li>
|
||||||
@ -107,6 +107,7 @@
|
|||||||
<p>Connects to a MQTT broker and publishes messages.</p>
|
<p>Connects to a MQTT broker and publishes messages.</p>
|
||||||
<p><code>msg.payload</code> is used as the payload of the published message.
|
<p><code>msg.payload</code> is used as the payload of the published message.
|
||||||
If it contains an Object it will be converted to JSON before being sent.
|
If it contains an Object it will be converted to JSON before being sent.
|
||||||
|
If it contains a binary Buffer the message will be published as-is.
|
||||||
</p>
|
</p>
|
||||||
<p>The topic used can be configured in the node or, if left blank, can be set
|
<p>The topic used can be configured in the node or, if left blank, can be set
|
||||||
by <code>msg.topic</code>.</p>
|
by <code>msg.topic</code>.</p>
|
||||||
@ -299,7 +300,7 @@
|
|||||||
id: "mqtt-broker-tab-will",
|
id: "mqtt-broker-tab-will",
|
||||||
label: this._("mqtt.tabs-label.will")
|
label: this._("mqtt.tabs-label.will")
|
||||||
});
|
});
|
||||||
setTimeout(function() { tabs.resize()},0);
|
setTimeout(function() { tabs.resize(); },0);
|
||||||
if (typeof this.cleansession === 'undefined') {
|
if (typeof this.cleansession === 'undefined') {
|
||||||
this.cleansession = true;
|
this.cleansession = true;
|
||||||
$("#node-config-input-cleansession").prop("checked",true);
|
$("#node-config-input-cleansession").prop("checked",true);
|
||||||
|
@ -66,16 +66,16 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
// If the config node is missing certain options (it was probably deployed prior to an update to the node code),
|
// If the config node is missing certain options (it was probably deployed prior to an update to the node code),
|
||||||
// select/generate sensible options for the new fields
|
// select/generate sensible options for the new fields
|
||||||
if (typeof this.usetls === 'undefined'){
|
if (typeof this.usetls === 'undefined') {
|
||||||
this.usetls = false;
|
this.usetls = false;
|
||||||
}
|
}
|
||||||
if (typeof this.compatmode === 'undefined'){
|
if (typeof this.compatmode === 'undefined') {
|
||||||
this.compatmode = true;
|
this.compatmode = true;
|
||||||
}
|
}
|
||||||
if (typeof this.verifyservercert === 'undefined'){
|
if (typeof this.verifyservercert === 'undefined') {
|
||||||
this.verifyservercert = false;
|
this.verifyservercert = false;
|
||||||
}
|
}
|
||||||
if (typeof this.keepalive === 'undefined'){
|
if (typeof this.keepalive === 'undefined') {
|
||||||
this.keepalive = 60;
|
this.keepalive = 60;
|
||||||
} else if (typeof this.keepalive === 'string') {
|
} else if (typeof this.keepalive === 'string') {
|
||||||
this.keepalive = Number(this.keepalive);
|
this.keepalive = Number(this.keepalive);
|
||||||
@ -110,7 +110,7 @@ module.exports = function(RED) {
|
|||||||
this.options.keepalive = this.keepalive;
|
this.options.keepalive = this.keepalive;
|
||||||
this.options.clean = this.cleansession;
|
this.options.clean = this.cleansession;
|
||||||
this.options.reconnectPeriod = RED.settings.mqttReconnectTime||5000;
|
this.options.reconnectPeriod = RED.settings.mqttReconnectTime||5000;
|
||||||
if (this.compatmode == "true" || this.compatmode === true){
|
if (this.compatmode == "true" || this.compatmode === true) {
|
||||||
this.options.protocolId = 'MQIsdp';
|
this.options.protocolId = 'MQIsdp';
|
||||||
this.options.protocolVersion = 3;
|
this.options.protocolVersion = 3;
|
||||||
}
|
}
|
||||||
@ -140,14 +140,14 @@ module.exports = function(RED) {
|
|||||||
var node = this;
|
var node = this;
|
||||||
this.users = {};
|
this.users = {};
|
||||||
|
|
||||||
this.register = function(mqttNode){
|
this.register = function(mqttNode) {
|
||||||
node.users[mqttNode.id] = mqttNode;
|
node.users[mqttNode.id] = mqttNode;
|
||||||
if (Object.keys(node.users).length === 1) {
|
if (Object.keys(node.users).length === 1) {
|
||||||
node.connect();
|
node.connect();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.deregister = function(mqttNode,done){
|
this.deregister = function(mqttNode,done) {
|
||||||
delete node.users[mqttNode.id];
|
delete node.users[mqttNode.id];
|
||||||
if (node.closing) {
|
if (node.closing) {
|
||||||
return done();
|
return done();
|
||||||
@ -266,7 +266,7 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
if (Object.keys(sub).length === 0) {
|
if (Object.keys(sub).length === 0) {
|
||||||
delete node.subscriptions[topic];
|
delete node.subscriptions[topic];
|
||||||
if (node.connected){
|
if (node.connected) {
|
||||||
node.client.unsubscribe(topic);
|
node.client.unsubscribe(topic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -287,7 +287,7 @@ module.exports = function(RED) {
|
|||||||
qos: msg.qos || 0,
|
qos: msg.qos || 0,
|
||||||
retain: msg.retain || false
|
retain: msg.retain || false
|
||||||
};
|
};
|
||||||
node.client.publish(msg.topic, msg.payload, options, function (err){return});
|
node.client.publish(msg.topic, msg.payload, options, function(err) {return});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -298,7 +298,7 @@ module.exports = function(RED) {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
this.client.end();
|
this.client.end();
|
||||||
} else if (this.connecting) {
|
} else if (this.connecting || node.client.reconnecting) {
|
||||||
node.client.end();
|
node.client.end();
|
||||||
done();
|
done();
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user