mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Merge branch 'pr_1231' into 0.18
This commit is contained in:
commit
bedb2d943e
@ -187,10 +187,6 @@
|
||||
<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 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">
|
||||
<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">
|
||||
@ -264,10 +260,23 @@
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="mqtt-broker">
|
||||
<p>A minimum MQTT broker connection requires only a broker server address to be added to the default configuration.</p>
|
||||
<p>To secure the connection with SSL/TLS, a TLS Configuration must also be configured and selected.</p>
|
||||
<p>If you create a Client ID it must be unique to the broker you are connecting to.</p>
|
||||
<p>For more information about MQTT see the <a href="http://www.eclipse.org/paho/" target="_blank">Eclipse Paho</a> site.</p>
|
||||
<p>Configuration for a connection to an MQTT broker.</p>
|
||||
<p>This configuration will create a single connection to the broker which can
|
||||
then be reused by <code>MQTT In</code> and <code>MQTT Out</code> nodes.</p>
|
||||
<p>The node will generate a random Client ID if one is not set and the
|
||||
node is configured to use a Clean Session connection. If a Client ID is set,
|
||||
it must be unique to the broker you are connecting to.</p>
|
||||
<h4>Birth Message</h4>
|
||||
<p>This is a message that will be published on the configured topic whenever the
|
||||
connection is established.</p>
|
||||
<h4>Will Message</h4>
|
||||
<p>This is a message that will be published by the broker in the event the node
|
||||
unexpectedly loses its connection.</p>
|
||||
<h4>WebSockets</h4>
|
||||
<p>The node can be configured to use a WebSocket connection. To do so, the Server
|
||||
field should be configured with a full URI for the connection. For example:</p>
|
||||
<pre>ws://example.com:4000/mqtt</pre>
|
||||
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
@ -276,18 +285,17 @@
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
broker: {value:"",required:true},
|
||||
port: {value:1883,required:true,validate:RED.validators.number()},
|
||||
port: {value:1883,required:false,validate:RED.validators.number(true)},
|
||||
tls: {type:"tls-config",required: false},
|
||||
clientid: {value:"", validate: function(v) {
|
||||
if ($("#node-config-input-clientid").length) {
|
||||
// Currently editing the node
|
||||
return $("#node-config-input-cleansession").is(":checked") || (v||"").length > 0;
|
||||
} else {
|
||||
return (this.cleansession===undefined || this.cleansession) || (v||"").length > 0;
|
||||
}
|
||||
}},
|
||||
if ($("#node-config-input-clientid").length) {
|
||||
// Currently editing the node
|
||||
return $("#node-config-input-cleansession").is(":checked") || (v||"").length > 0;
|
||||
} else {
|
||||
return (this.cleansession===undefined || this.cleansession) || (v||"").length > 0;
|
||||
}
|
||||
}},
|
||||
usetls: {value: false},
|
||||
usews: {value: false},
|
||||
verifyservercert: { value: false},
|
||||
compatmode: { value: true},
|
||||
keepalive: {value:60,validate:RED.validators.number()},
|
||||
@ -306,15 +314,18 @@
|
||||
password: {type: "password"}
|
||||
},
|
||||
label: function() {
|
||||
var lab = this.name;
|
||||
if ((lab === undefined) || (lab ==="")) {
|
||||
var b = this.broker;
|
||||
if (b === "") { b = "undefined"; }
|
||||
lab = (this.clientid?this.clientid+"@":"")+b+":"+this.port;
|
||||
if (this.name) {
|
||||
return this.name;
|
||||
}
|
||||
var b = this.broker;
|
||||
if (b === "") { b = "undefined"; }
|
||||
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({
|
||||
@ -349,10 +360,6 @@
|
||||
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);
|
||||
@ -394,6 +401,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,50);
|
||||
|
||||
},
|
||||
oneditsave: function() {
|
||||
if (!$("#node-config-input-usetls").is(':checked')) {
|
||||
|
@ -90,23 +90,27 @@ module.exports = function(RED) {
|
||||
|
||||
// Create the URL to pass in to the MQTT.js library
|
||||
if (this.brokerurl === "") {
|
||||
if (this.usews) {
|
||||
if (this.usetls) {
|
||||
this.brokerurl="wss://";
|
||||
} else {
|
||||
this.brokerurl="ws://";
|
||||
}
|
||||
// if the broker may be ws:// or wss:// or even tcp://
|
||||
if (this.broker.indexOf("://") > -1) {
|
||||
this.brokerurl = this.broker;
|
||||
} else {
|
||||
// construct the std mqtt:// url
|
||||
if (this.usetls) {
|
||||
this.brokerurl="mqtts://";
|
||||
} else {
|
||||
this.brokerurl="mqtt://";
|
||||
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";
|
||||
}
|
||||
}
|
||||
if (this.broker !== "") {
|
||||
this.brokerurl = this.brokerurl+this.broker+":"+this.port;
|
||||
} else {
|
||||
this.brokerurl = this.brokerurl+"localhost:1883";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -315,7 +315,6 @@
|
||||
"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"
|
||||
|
Loading…
Reference in New Issue
Block a user