diff --git a/nodes/core/io/10-mqtt.html b/nodes/core/io/10-mqtt.html
index 37c065b9f..1f11a3439 100644
--- a/nodes/core/io/10-mqtt.html
+++ b/nodes/core/io/10-mqtt.html
@@ -173,7 +173,7 @@
-
+
@@ -256,7 +256,8 @@
@@ -266,7 +267,7 @@
category: 'config',
defaults: {
broker: {value:"",required:true},
- port: {value:1883,required:true,validate:RED.validators.number()},
+ port: {value:1883,required:false,validate:function(v){ return RED.validators.number() || (v === null) }},
tls: {type:"tls-config",required: false},
clientid: {value:"", validate: function(v) {
if ($("#node-config-input-clientid").length) {
@@ -297,7 +298,13 @@
label: function() {
var b = this.broker;
if (b === "") { b = "undefined"; }
- return (this.clientid?this.clientid+"@":"")+b+":"+this.port;
+ var lab = "";
+ lab = (this.clientid?this.clientid+"@":"")+b;
+ if (b.indexOf("://") === -1){
+ if (!this.port){ lab = lab + ":1883"; }
+ else { lab = lab + ":" + this.port; }
+ }
+ return lab;
},
oneditprepare: function () {
var tabs = RED.tabs.create({
@@ -373,6 +380,28 @@
$("#node-config-input-cleansession").on("click",function() {
updateClientId();
});
+
+ function updatePortEntry(){
+ var disabled = $("#node-config-input-port").prop("disabled");
+ if ($("#node-config-input-broker").val().indexOf("://") === -1){
+ if (disabled){
+ $("#node-config-input-port").prop("disabled", false);
+ }
+ }
+ else {
+ if (!disabled){
+ $("#node-config-input-port").prop("disabled", true);
+ }
+ }
+ }
+ $("#node-config-input-broker").change(function() {
+ updatePortEntry();
+ });
+ $("#node-config-input-broker").on( "keyup", function() {
+ updatePortEntry();
+ });
+ setTimeout(updatePortEntry());
+
},
oneditsave: function() {
if (!$("#node-config-input-usetls").is(':checked')) {
diff --git a/nodes/core/io/10-mqtt.js b/nodes/core/io/10-mqtt.js
index b01df652b..87c7bfb13 100644
--- a/nodes/core/io/10-mqtt.js
+++ b/nodes/core/io/10-mqtt.js
@@ -86,15 +86,27 @@ 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 the broken may be ws:// or wss:// or even tcp://
+ if (this.broker.indexOf("://") > -1) {
+ this.brokerurl = this.broker;
} else {
- this.brokerurl="mqtt://";
- }
- if (this.broker !== "") {
- this.brokerurl = this.brokerurl+this.broker+":"+this.port;
- } else {
- this.brokerurl = this.brokerurl+"localhost:1883";
+ // construct the std mqtt:// url
+ if (this.usetls) {
+ this.brokerurl="mqtts://";
+ } else {
+ this.brokerurl="mqtt://";
+ }
+ if (this.broker !== "") {
+ this.brokerurl = this.brokerurl+this.broker+":";
+ // port now defaults to 1883 if unset.
+ if (!this.port){
+ this.brokerurl = this.brokerurl+"1883";
+ } else {
+ this.brokerurl = this.brokerurl+this.port;
+ }
+ } else {
+ this.brokerurl = this.brokerurl+"localhost:1883";
+ }
}
}