Skip to content

Commit

Permalink
Refactor to use the already existing autoUnsubscribe property
Browse files Browse the repository at this point in the history
The tests had an unused property called autoUnsubscribe. I refactored
the code to use this wording too.
  • Loading branch information
flying7eleven committed Feb 27, 2023
1 parent b5dfd62 commit 8dcc530
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
14 changes: 7 additions & 7 deletions packages/node_modules/@node-red/nodes/core/network/10-mqtt.html
Expand Up @@ -250,9 +250,9 @@
</label>
</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 for="node-config-input-autoUnsubscribe" style="width: auto;">
<input type="checkbox" id="node-config-input-autoUnsubscribe" style="position: relative;vertical-align: bottom; top: -2px; width: 15px;height: 15px;">
<span id="node-config-input-autoUnsubscribe-label" data-i18n="mqtt.label.autoUnsubscribe"></span>
</label>
</div>
<div class="form-row mqtt5">
Expand Down Expand Up @@ -511,7 +511,7 @@
label: RED._("node-red:mqtt.label.keepalive"),
validate:RED.validators.number(false)},
cleansession: {value: true},
unsubscribeOnDisconnect: {value: true},
autoUnsubscribe: {value: true},
birthTopic: {value:"", validate:validateMQTTPublishTopic},
birthQos: {value:"0"},
birthRetain: {value:"false"},
Expand Down Expand Up @@ -627,9 +627,9 @@
this.cleansession = 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.autoUnsubscribe === 'undefined') {
this.autoUnsubscribe = true;
$("#node-config-input-autoUnsubscribe").prop("checked",true);
}
if (typeof this.usetls === 'undefined') {
this.usetls = false;
Expand Down
12 changes: 6 additions & 6 deletions packages/node_modules/@node-red/nodes/core/network/10-mqtt.js
Expand Up @@ -482,7 +482,7 @@ module.exports = function(RED) {
setIfHasProperty(opts, node, "protocolVersion", init);
setIfHasProperty(opts, node, "keepalive", init);
setIfHasProperty(opts, node, "cleansession", init);
setIfHasProperty(opts, node, "unsubscribeOnDisconnect", init);
setIfHasProperty(opts, node, "autoUnsubscribe", init);
setIfHasProperty(opts, node, "topicAliasMaximum", init);
setIfHasProperty(opts, node, "maximumPacketSize", init);
setIfHasProperty(opts, node, "receiveMaximum", init);
Expand Down Expand Up @@ -591,8 +591,8 @@ module.exports = function(RED) {
if (typeof node.cleansession === 'undefined') {
node.cleansession = true;
}
if (typeof node.unsubscribeOnDisconnect === 'undefined') {
node.unsubscribeOnDisconnect = true;
if (typeof node.autoUnsubscribe === 'undefined') {
node.autoUnsubscribe = true;
}

//use url or build a url from usetls://broker:port
Expand Down Expand Up @@ -664,7 +664,7 @@ module.exports = function(RED) {
node.options.password = node.password;
node.options.keepalive = node.keepalive;
node.options.clean = node.cleansession;
node.options.unsubscribeOnDisconnect = node.unsubscribeOnDisconnect;
node.options.autoUnsubscribe = node.autoUnsubscribe;
node.options.clientId = node.clientid || 'nodered_' + RED.util.generateId();
node.options.reconnectPeriod = RED.settings.mqttReconnectTime||5000;
delete node.options.protocolId; //V4+ default
Expand Down Expand Up @@ -1233,14 +1233,14 @@ module.exports = function(RED) {
node.on('close', function(removed, done) {
if (node.brokerConn) {
if(node.isDynamic) {
if (node.brokerConn.options.unsubscribeOnDisconnect) {
if (node.brokerConn.options.autoUnsubscribe) {
Object.keys(node.dynamicSubs).forEach(function (topic) {
node.brokerConn.unsubscribe(topic, node.id, removed);
});
node.dynamicSubs = {};
}
} else {
if (node.brokerConn.options.unsubscribeOnDisconnect) {
if (node.brokerConn.options.autoUnsubscribe) {
node.brokerConn.unsubscribe(node.topic, node.id, removed);
}
}
Expand Down
Expand Up @@ -362,7 +362,7 @@
"port": "Port",
"keepalive": "Keep-Alive",
"cleansession": "Bereinigte Sitzung (clean session) verwenden",
"unsubscribeOnDisconnect": "Abonnement bei Verbindungsende automatisch beenden",
"autoUnsubscribe": "Abonnement bei Verbindungsende automatisch beenden",
"cleanstart": "Verwende bereinigten Start",
"use-tls": "TLS",
"tls-config": "TLS-Konfiguration",
Expand Down
Expand Up @@ -414,7 +414,7 @@
"port": "Port",
"keepalive": "Keep Alive",
"cleansession": "Use clean session",
"unsubscribeOnDisconnect": "Automatically unsubscribe when disconnecting",
"autoUnsubscribe": "Automatically unsubscribe when disconnecting",
"cleanstart": "Use clean start",
"use-tls": "Use TLS",
"tls-config": "TLS Configuration",
Expand Down

0 comments on commit 8dcc530

Please sign in to comment.