mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add an option to not unsubscribe topics on disconnect
This commit is contained in:
parent
910f6134f6
commit
b5dfd62c99
@ -249,6 +249,12 @@
|
|||||||
<span id="node-config-input-cleansession-label" data-i18n="mqtt.label.cleansession"></span>
|
<span id="node-config-input-cleansession-label" data-i18n="mqtt.label.cleansession"></span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-row mqtt-persistence">
|
||||||
|
<label for="node-config-input-unsubscribeOnDisconnect" style="width: auto;">
|
||||||
|
<input type="checkbox" id="node-config-input-unsubscribeOnDisconnect" style="position: relative;vertical-align: bottom; top: -2px; width: 15px;height: 15px;">
|
||||||
|
<span id="node-config-input-unsubscribeOnDisconnect-label" data-i18n="mqtt.label.unsubscribeOnDisconnect"></span>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
<div class="form-row mqtt5">
|
<div class="form-row mqtt5">
|
||||||
<label style="width:auto" for="node-config-input-sessionExpiry"><span data-i18n="mqtt.label.sessionExpiry"></span></label>
|
<label style="width:auto" for="node-config-input-sessionExpiry"><span data-i18n="mqtt.label.sessionExpiry"></span></label>
|
||||||
<input type="number" min="0" id="node-config-input-sessionExpiry" style="width: 100px" >
|
<input type="number" min="0" id="node-config-input-sessionExpiry" style="width: 100px" >
|
||||||
@ -505,6 +511,7 @@
|
|||||||
label: RED._("node-red:mqtt.label.keepalive"),
|
label: RED._("node-red:mqtt.label.keepalive"),
|
||||||
validate:RED.validators.number(false)},
|
validate:RED.validators.number(false)},
|
||||||
cleansession: {value: true},
|
cleansession: {value: true},
|
||||||
|
unsubscribeOnDisconnect: {value: true},
|
||||||
birthTopic: {value:"", validate:validateMQTTPublishTopic},
|
birthTopic: {value:"", validate:validateMQTTPublishTopic},
|
||||||
birthQos: {value:"0"},
|
birthQos: {value:"0"},
|
||||||
birthRetain: {value:"false"},
|
birthRetain: {value:"false"},
|
||||||
@ -620,6 +627,10 @@
|
|||||||
this.cleansession = true;
|
this.cleansession = true;
|
||||||
$("#node-config-input-cleansession").prop("checked",true);
|
$("#node-config-input-cleansession").prop("checked",true);
|
||||||
}
|
}
|
||||||
|
if (typeof this.unsubscribeOnDisconnect === 'undefined') {
|
||||||
|
this.unsubscribeOnDisconnect = true;
|
||||||
|
$("#node-config-input-unsubscribeOnDisconnect").prop("checked",true);
|
||||||
|
}
|
||||||
if (typeof this.usetls === 'undefined') {
|
if (typeof this.usetls === 'undefined') {
|
||||||
this.usetls = false;
|
this.usetls = false;
|
||||||
$("#node-config-input-usetls").prop("checked",false);
|
$("#node-config-input-usetls").prop("checked",false);
|
||||||
@ -635,6 +646,14 @@
|
|||||||
if (typeof this.protocolVersion === 'undefined') {
|
if (typeof this.protocolVersion === 'undefined') {
|
||||||
this.protocolVersion = 4;
|
this.protocolVersion = 4;
|
||||||
}
|
}
|
||||||
|
$("#node-config-input-cleansession").on("change", function() {
|
||||||
|
var useCleanSession = $("#node-config-input-cleansession").is(':checked');
|
||||||
|
if(useCleanSession) {
|
||||||
|
$("div.form-row.mqtt-persistence").hide();
|
||||||
|
} else {
|
||||||
|
$("div.form-row.mqtt-persistence").show();
|
||||||
|
}
|
||||||
|
});
|
||||||
$("#node-config-input-protocolVersion").on("change", function() {
|
$("#node-config-input-protocolVersion").on("change", function() {
|
||||||
var v5 = $("#node-config-input-protocolVersion").val() == "5";
|
var v5 = $("#node-config-input-protocolVersion").val() == "5";
|
||||||
if(v5) {
|
if(v5) {
|
||||||
|
@ -482,6 +482,7 @@ module.exports = function(RED) {
|
|||||||
setIfHasProperty(opts, node, "protocolVersion", init);
|
setIfHasProperty(opts, node, "protocolVersion", init);
|
||||||
setIfHasProperty(opts, node, "keepalive", init);
|
setIfHasProperty(opts, node, "keepalive", init);
|
||||||
setIfHasProperty(opts, node, "cleansession", init);
|
setIfHasProperty(opts, node, "cleansession", init);
|
||||||
|
setIfHasProperty(opts, node, "unsubscribeOnDisconnect", init);
|
||||||
setIfHasProperty(opts, node, "topicAliasMaximum", init);
|
setIfHasProperty(opts, node, "topicAliasMaximum", init);
|
||||||
setIfHasProperty(opts, node, "maximumPacketSize", init);
|
setIfHasProperty(opts, node, "maximumPacketSize", init);
|
||||||
setIfHasProperty(opts, node, "receiveMaximum", init);
|
setIfHasProperty(opts, node, "receiveMaximum", init);
|
||||||
@ -590,6 +591,9 @@ module.exports = function(RED) {
|
|||||||
if (typeof node.cleansession === 'undefined') {
|
if (typeof node.cleansession === 'undefined') {
|
||||||
node.cleansession = true;
|
node.cleansession = true;
|
||||||
}
|
}
|
||||||
|
if (typeof node.unsubscribeOnDisconnect === 'undefined') {
|
||||||
|
node.unsubscribeOnDisconnect = true;
|
||||||
|
}
|
||||||
|
|
||||||
//use url or build a url from usetls://broker:port
|
//use url or build a url from usetls://broker:port
|
||||||
if (node.url && node.brokerurl !== node.url) {
|
if (node.url && node.brokerurl !== node.url) {
|
||||||
@ -660,6 +664,7 @@ module.exports = function(RED) {
|
|||||||
node.options.password = node.password;
|
node.options.password = node.password;
|
||||||
node.options.keepalive = node.keepalive;
|
node.options.keepalive = node.keepalive;
|
||||||
node.options.clean = node.cleansession;
|
node.options.clean = node.cleansession;
|
||||||
|
node.options.unsubscribeOnDisconnect = node.unsubscribeOnDisconnect;
|
||||||
node.options.clientId = node.clientid || 'nodered_' + RED.util.generateId();
|
node.options.clientId = node.clientid || 'nodered_' + RED.util.generateId();
|
||||||
node.options.reconnectPeriod = RED.settings.mqttReconnectTime||5000;
|
node.options.reconnectPeriod = RED.settings.mqttReconnectTime||5000;
|
||||||
delete node.options.protocolId; //V4+ default
|
delete node.options.protocolId; //V4+ default
|
||||||
@ -1228,12 +1233,16 @@ module.exports = function(RED) {
|
|||||||
node.on('close', function(removed, done) {
|
node.on('close', function(removed, done) {
|
||||||
if (node.brokerConn) {
|
if (node.brokerConn) {
|
||||||
if(node.isDynamic) {
|
if(node.isDynamic) {
|
||||||
|
if (node.brokerConn.options.unsubscribeOnDisconnect) {
|
||||||
Object.keys(node.dynamicSubs).forEach(function (topic) {
|
Object.keys(node.dynamicSubs).forEach(function (topic) {
|
||||||
node.brokerConn.unsubscribe(topic, node.id, removed);
|
node.brokerConn.unsubscribe(topic, node.id, removed);
|
||||||
});
|
});
|
||||||
node.dynamicSubs = {};
|
node.dynamicSubs = {};
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
node.brokerConn.unsubscribe(node.topic,node.id, removed);
|
if (node.brokerConn.options.unsubscribeOnDisconnect) {
|
||||||
|
node.brokerConn.unsubscribe(node.topic, node.id, removed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
node.brokerConn.deregister(node, done, removed);
|
node.brokerConn.deregister(node, done, removed);
|
||||||
node.brokerConn = null;
|
node.brokerConn = null;
|
||||||
|
@ -362,6 +362,7 @@
|
|||||||
"port": "Port",
|
"port": "Port",
|
||||||
"keepalive": "Keep-Alive",
|
"keepalive": "Keep-Alive",
|
||||||
"cleansession": "Bereinigte Sitzung (clean session) verwenden",
|
"cleansession": "Bereinigte Sitzung (clean session) verwenden",
|
||||||
|
"unsubscribeOnDisconnect": "Abonnement bei Verbindungsende automatisch beenden",
|
||||||
"cleanstart": "Verwende bereinigten Start",
|
"cleanstart": "Verwende bereinigten Start",
|
||||||
"use-tls": "TLS",
|
"use-tls": "TLS",
|
||||||
"tls-config": "TLS-Konfiguration",
|
"tls-config": "TLS-Konfiguration",
|
||||||
|
@ -414,6 +414,7 @@
|
|||||||
"port": "Port",
|
"port": "Port",
|
||||||
"keepalive": "Keep Alive",
|
"keepalive": "Keep Alive",
|
||||||
"cleansession": "Use clean session",
|
"cleansession": "Use clean session",
|
||||||
|
"unsubscribeOnDisconnect": "Automatically unsubscribe when disconnecting",
|
||||||
"cleanstart": "Use clean start",
|
"cleanstart": "Use clean start",
|
||||||
"use-tls": "Use TLS",
|
"use-tls": "Use TLS",
|
||||||
"tls-config": "TLS Configuration",
|
"tls-config": "TLS Configuration",
|
||||||
|
Loading…
Reference in New Issue
Block a user