Skip to content

Commit

Permalink
Add support for MQTT over web sockets.
Browse files Browse the repository at this point in the history
  • Loading branch information
tboman committed Sep 5, 2018
1 parent 72b8dbb commit 052f1aa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
27 changes: 27 additions & 0 deletions nodes/core/io/10-mqtt.html
Expand Up @@ -180,6 +180,13 @@ <h3>Details</h3>
<label for="node-config-input-port" style="margin-left:20px; width:43px; "> <span data-i18n="mqtt.label.port"></span></label>
<input type="text" id="node-config-input-port" data-i18n="[placeholder]mqtt.label.port" style="width:55px">
</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 id="node-config-row-ws" class="hide">
<label style="width: auto; margin-left: 20px; margin-right: 10px;" for="node-config-input-ws"><span data-i18n="mqtt.label.ws-config"></span></label><input style="width: 300px;" type="text" id="node-config-input-tls">
</div>
</div>
<div class="form-row">
<input type="checkbox" id="node-config-input-usetls" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-config-input-usetls" style="width: auto" data-i18n="mqtt.label.use-tls"></label>
Expand Down Expand Up @@ -335,6 +342,7 @@ <h4>WebSockets</h4>
}
}},
usetls: {value: false},
usews: {value: false},
verifyservercert: { value: false},
compatmode: { value: true},
keepalive: {value:60,validate:RED.validators.number()},
Expand Down Expand Up @@ -428,6 +436,10 @@ <h4>WebSockets</h4>
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);
Expand Down Expand Up @@ -460,6 +472,18 @@ <h4>WebSockets</h4>
$("#node-config-input-usetls").on("click",function() {
updateTLSOptions();
});

function updateWSOptions() {
if ($("#node-config-input-usews").is(':checked')) {
$("#node-config-row-ws").show();
} else {
$("#node-config-row-ws").hide();
}
}
updateWSOptions();
$("#node-config-input-usews").on("click",function() {
updateWSOptions();
});
var node = this;
function updateClientId() {
if ($("#node-config-input-cleansession").is(":checked")) {
Expand Down Expand Up @@ -500,6 +524,9 @@ <h4>WebSockets</h4>
if (!$("#node-config-input-usetls").is(':checked')) {
$("#node-config-input-tls").val("");
}
if (!$("#node-config-input-usews").is(':checked')) {
$("#node-config-input-ws").val("");
}
}
});
</script>
7 changes: 4 additions & 3 deletions nodes/core/io/10-mqtt.js
Expand Up @@ -136,10 +136,11 @@ module.exports = function(RED) {
}
} else {
// construct the std mqtt:// url
if (this.usetls) {
this.brokerurl="mqtts://";
let tlsPrefix = (this.usetls) ? "s" : "";
if (this.usetws) {
this.brokerurl="ws" + tlsPrefix + "://";
} else {
this.brokerurl="mqtt://";
this.brokerurl="mqtt" + tlsPrefix + "://";
}
if (this.broker !== "") {
this.brokerurl = this.brokerurl+this.broker+":";
Expand Down
1 change: 1 addition & 0 deletions nodes/core/locales/en-US/messages.json
Expand Up @@ -332,6 +332,7 @@
"cleansession": "Use clean session",
"use-tls": "Enable secure (SSL/TLS) connection",
"tls-config":"TLS Configuration",
"use-ws": "Enable MQTT over web sockets",
"verify-server-cert":"Verify server certificate",
"compatmode": "Use legacy MQTT 3.1 support"
},
Expand Down

0 comments on commit 052f1aa

Please sign in to comment.