1
0
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:
Nick O'Leary 2018-01-11 22:46:18 +00:00
commit bedb2d943e
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
3 changed files with 73 additions and 41 deletions

View File

@ -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"> <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">
@ -264,10 +260,23 @@
</script> </script>
<script type="text/x-red" data-help-name="mqtt-broker"> <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>Configuration for a connection to an MQTT broker.</p>
<p>To secure the connection with SSL/TLS, a TLS Configuration must also be configured and selected.</p> <p>This configuration will create a single connection to the broker which can
<p>If you create a Client ID it must be unique to the broker you are connecting to.</p> then be reused by <code>MQTT In</code> and <code>MQTT Out</code> nodes.</p>
<p>For more information about MQTT see the <a href="http://www.eclipse.org/paho/" target="_blank">Eclipse Paho</a> site.</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>
<script type="text/javascript"> <script type="text/javascript">
@ -276,7 +285,7 @@
defaults: { defaults: {
name: {value:""}, name: {value:""},
broker: {value:"",required:true}, 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}, tls: {type:"tls-config",required: false},
clientid: {value:"", validate: function(v) { clientid: {value:"", validate: function(v) {
if ($("#node-config-input-clientid").length) { if ($("#node-config-input-clientid").length) {
@ -287,7 +296,6 @@
} }
}}, }},
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()},
@ -306,15 +314,18 @@
password: {type: "password"} password: {type: "password"}
}, },
label: function() { label: function() {
var lab = this.name; if (this.name) {
if ((lab === undefined) || (lab ==="")) { return this.name;
}
var b = this.broker; var b = this.broker;
if (b === "") { b = "undefined"; } if (b === "") { b = "undefined"; }
lab = (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; return lab;
}, },
oneditprepare: function () { oneditprepare: function () {
var tabs = RED.tabs.create({ var tabs = RED.tabs.create({
@ -349,10 +360,6 @@
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);
@ -394,6 +401,28 @@
$("#node-config-input-cleansession").on("click",function() { $("#node-config-input-cleansession").on("click",function() {
updateClientId(); 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() { oneditsave: function() {
if (!$("#node-config-input-usetls").is(':checked')) { if (!$("#node-config-input-usetls").is(':checked')) {

View File

@ -90,25 +90,29 @@ 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.usews) { // if the broker may be ws:// or wss:// or even tcp://
if (this.usetls) { if (this.broker.indexOf("://") > -1) {
this.brokerurl="wss://"; this.brokerurl = this.broker;
} else {
this.brokerurl="ws://";
}
} else { } else {
// construct the std mqtt:// url
if (this.usetls) { if (this.usetls) {
this.brokerurl="mqtts://"; this.brokerurl="mqtts://";
} else { } else {
this.brokerurl="mqtt://"; this.brokerurl="mqtt://";
} }
}
if (this.broker !== "") { if (this.broker !== "") {
this.brokerurl = this.brokerurl+this.broker+":"+this.port; 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 { } else {
this.brokerurl = this.brokerurl+"localhost:1883"; this.brokerurl = this.brokerurl+"localhost:1883";
} }
} }
}
if (!this.cleansession && !this.clientid) { if (!this.cleansession && !this.clientid) {
this.cleansession = true; this.cleansession = true;

View File

@ -315,7 +315,6 @@
"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"