1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Add MQTT via WebSocket communication option (#1544)

* Add MQTT via WebSocket communication option

Add option in MQTT broker configuration node to enable MQTT via WebSoket comunication

* MQTT over WS error correction

Minimal correction of values and erase debug console.log unnecessary

* original package.json

Erase some changes on grunt build at package.json. Erase package-lock.json and back to the original package.json

* .gitignore

* .gitignore again

* No tabs
This commit is contained in:
delbozkester 2018-01-11 15:22:02 -06:00 committed by Nick O'Leary
parent 9ba011003a
commit af5df890a5
3 changed files with 25 additions and 3 deletions

View File

@ -187,6 +187,10 @@
<label style="width: auto; margin-left: 20px; margin-right: 10px;" for="node-config-input-tls"><span data-i18n="mqtt.label.tls-config"></span></label><input style="width: 300px;" type="text" id="node-config-input-tls"> <label style="width: auto; margin-left: 20px; margin-right: 10px;" for="node-config-input-tls"><span data-i18n="mqtt.label.tls-config"></span></label><input style="width: 300px;" type="text" id="node-config-input-tls">
</div> </div>
</div> </div>
<div class="form-row">
<input type="checkbox" id="node-config-input-usews" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-config-input-usews" style="width: auto;" data-i18n="mqtt.label.use-ws"></label>
</div>
<div class="form-row"> <div class="form-row">
<label for="node-config-input-clientid"><i class="fa fa-tag"></i> <span data-i18n="mqtt.label.clientid"></span></label> <label for="node-config-input-clientid"><i class="fa fa-tag"></i> <span data-i18n="mqtt.label.clientid"></span></label>
<input type="text" id="node-config-input-clientid" data-i18n="[placeholder]mqtt.placeholder.clientid"> <input type="text" id="node-config-input-clientid" data-i18n="[placeholder]mqtt.placeholder.clientid">
@ -283,6 +287,7 @@
} }
}}, }},
usetls: {value: false}, usetls: {value: false},
usews: {value: false},
verifyservercert: { value: false}, verifyservercert: { value: false},
compatmode: { value: true}, compatmode: { value: true},
keepalive: {value:60,validate:RED.validators.number()}, keepalive: {value:60,validate:RED.validators.number()},
@ -344,6 +349,10 @@
this.usetls = false; this.usetls = false;
$("#node-config-input-usetls").prop("checked",false); $("#node-config-input-usetls").prop("checked",false);
} }
if (typeof this.usews === 'undefined') {
this.usews = false;
$("#node-config-input-usews").prop('checked', false);
}
if (typeof this.compatmode === 'undefined') { if (typeof this.compatmode === 'undefined') {
this.compatmode = true; this.compatmode = true;
$("#node-config-input-compatmode").prop('checked', true); $("#node-config-input-compatmode").prop('checked', true);

View File

@ -36,6 +36,7 @@ module.exports = function(RED) {
this.port = n.port; this.port = n.port;
this.clientid = n.clientid; this.clientid = n.clientid;
this.usetls = n.usetls; this.usetls = n.usetls;
this.usews = n.usews;
this.verifyservercert = n.verifyservercert; this.verifyservercert = n.verifyservercert;
this.compatmode = n.compatmode; this.compatmode = n.compatmode;
this.keepalive = n.keepalive; this.keepalive = n.keepalive;
@ -69,6 +70,9 @@ module.exports = function(RED) {
if (typeof this.usetls === 'undefined') { if (typeof this.usetls === 'undefined') {
this.usetls = false; this.usetls = false;
} }
if (typeof this.usews === 'undefined') {
this.usews = false;
}
if (typeof this.compatmode === 'undefined') { if (typeof this.compatmode === 'undefined') {
this.compatmode = true; this.compatmode = true;
} }
@ -86,10 +90,18 @@ module.exports = function(RED) {
// Create the URL to pass in to the MQTT.js library // Create the URL to pass in to the MQTT.js library
if (this.brokerurl === "") { if (this.brokerurl === "") {
if (this.usetls) { if (this.usews) {
this.brokerurl="mqtts://"; if (this.usetls) {
this.brokerurl="wss://";
} else {
this.brokerurl="ws://";
}
} else { } else {
this.brokerurl="mqtt://"; if (this.usetls) {
this.brokerurl="mqtts://";
} else {
this.brokerurl="mqtt://";
}
} }
if (this.broker !== "") { if (this.broker !== "") {
this.brokerurl = this.brokerurl+this.broker+":"+this.port; this.brokerurl = this.brokerurl+this.broker+":"+this.port;

View File

@ -314,6 +314,7 @@
"keepalive": "Keep alive time (s)", "keepalive": "Keep alive time (s)",
"cleansession": "Use clean session", "cleansession": "Use clean session",
"use-tls": "Enable secure (SSL/TLS) connection", "use-tls": "Enable secure (SSL/TLS) connection",
"use-ws": "Enable MQTT over WebSocket connection",
"tls-config":"TLS Configuration", "tls-config":"TLS Configuration",
"verify-server-cert":"Verify server certificate", "verify-server-cert":"Verify server certificate",
"compatmode": "Use legacy MQTT 3.1 support" "compatmode": "Use legacy MQTT 3.1 support"