From af5df890a5a5df7a2b356fdbf0ab73d8a0cff3f2 Mon Sep 17 00:00:00 2001 From: delbozkester Date: Thu, 11 Jan 2018 15:22:02 -0600 Subject: [PATCH] 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 --- nodes/core/io/10-mqtt.html | 9 +++++++++ nodes/core/io/10-mqtt.js | 18 +++++++++++++++--- nodes/core/locales/en-US/messages.json | 1 + 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/nodes/core/io/10-mqtt.html b/nodes/core/io/10-mqtt.html index 4e4613ba7..70767edb4 100644 --- a/nodes/core/io/10-mqtt.html +++ b/nodes/core/io/10-mqtt.html @@ -187,6 +187,10 @@ +
+ + +
@@ -283,6 +287,7 @@ } }}, usetls: {value: false}, + usews: {value: false}, verifyservercert: { value: false}, compatmode: { value: true}, keepalive: {value:60,validate:RED.validators.number()}, @@ -344,6 +349,10 @@ this.usetls = 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') { this.compatmode = true; $("#node-config-input-compatmode").prop('checked', true); diff --git a/nodes/core/io/10-mqtt.js b/nodes/core/io/10-mqtt.js index b01df652b..80059858e 100644 --- a/nodes/core/io/10-mqtt.js +++ b/nodes/core/io/10-mqtt.js @@ -36,6 +36,7 @@ module.exports = function(RED) { this.port = n.port; this.clientid = n.clientid; this.usetls = n.usetls; + this.usews = n.usews; this.verifyservercert = n.verifyservercert; this.compatmode = n.compatmode; this.keepalive = n.keepalive; @@ -69,6 +70,9 @@ module.exports = function(RED) { if (typeof this.usetls === 'undefined') { this.usetls = false; } + if (typeof this.usews === 'undefined') { + this.usews = false; + } if (typeof this.compatmode === 'undefined') { this.compatmode = true; } @@ -86,10 +90,18 @@ module.exports = function(RED) { // Create the URL to pass in to the MQTT.js library if (this.brokerurl === "") { - if (this.usetls) { - this.brokerurl="mqtts://"; + if (this.usews) { + if (this.usetls) { + this.brokerurl="wss://"; + } else { + this.brokerurl="ws://"; + } } else { - this.brokerurl="mqtt://"; + if (this.usetls) { + this.brokerurl="mqtts://"; + } else { + this.brokerurl="mqtt://"; + } } if (this.broker !== "") { this.brokerurl = this.brokerurl+this.broker+":"+this.port; diff --git a/nodes/core/locales/en-US/messages.json b/nodes/core/locales/en-US/messages.json index 8562b961f..d201174d9 100644 --- a/nodes/core/locales/en-US/messages.json +++ b/nodes/core/locales/en-US/messages.json @@ -314,6 +314,7 @@ "keepalive": "Keep alive time (s)", "cleansession": "Use clean session", "use-tls": "Enable secure (SSL/TLS) connection", + "use-ws": "Enable MQTT over WebSocket connection", "tls-config":"TLS Configuration", "verify-server-cert":"Verify server certificate", "compatmode": "Use legacy MQTT 3.1 support"