1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Add TLS options to WebSocket client

This commit is contained in:
Nick O'Leary 2018-01-25 20:26:35 +00:00
parent 45913e5ee8
commit 73ee657d74
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
4 changed files with 31 additions and 6 deletions

View File

@ -184,7 +184,6 @@ module.exports = function(RED) {
this.connect = function () {
if (!node.connected && !node.connecting) {
node.connecting = true;
console.log("going for connect");
try {
node.client = mqtt.connect(node.brokerurl ,node.options);
node.client.setMaxListeners(0);

View File

@ -180,12 +180,24 @@
category: 'config',
defaults: {
path: {value:"",required:true,validate:RED.validators.regex(/^((?!\/debug\/ws).)*$/)},
tls: {type:"tls-config",required: false},
wholemsg: {value:"false"}
},
inputs:0,
outputs:0,
label: function() {
return this.path;
},
oneditprepare: function() {
$("#node-config-input-path").on("change keyup paste",function() {
$(".node-config-row-tls").toggle(/^wss:/i.test($(this).val()))
});
$("#node-config-input-path").change();
},
oneditsave: function() {
if (!/^wss:/i.test($("#node-config-input-path").val())) {
$("#node-config-input-tls").val("_ADD_");
}
}
});
@ -235,7 +247,7 @@
<input id="node-config-input-path" type="text" placeholder="/ws/example">
</div>
<div class="form-row">
<label for="node-config-input-wholemsg">&nbsp;</label>
<label for="node-config-input-wholemsg"></label>
<select type="text" id="node-config-input-wholemsg" style="width: 70%;">
<option value="false" data-i18n="websocket.payload"></option>
<option value="true" data-i18n="websocket.message"></option>
@ -257,8 +269,13 @@
<label for="node-config-input-path"><i class="fa fa-bookmark"></i> <span data-i18n="websocket.label.url"></span></label>
<input id="node-config-input-path" type="text" placeholder="ws://example.com/ws">
</div>
<div class="form-row node-config-row-tls hide">
<label for="node-config-input-tls" data-i18n="httpin.tls-config"></label>
<input type="text" id="node-config-input-tls">
</div>
<div class="form-row">
<label for="node-config-input-wholemsg">&nbsp;</label>
<label for="node-config-input-wholemsg" data-i18n="websocket.sendrec"></label>
<select type="text" id="node-config-input-wholemsg" style="width: 70%;">
<option value="false" data-i18n="websocket.payload"></option>
<option value="true" data-i18n="websocket.message"></option>

View File

@ -34,10 +34,18 @@ module.exports = function(RED) {
// match absolute url
node.isServer = !/^ws{1,2}:\/\//i.test(node.path);
node.closing = false;
node.tls = n.tls;
function startconn() { // Connect to remote endpoint
node.tout = null;
var socket = new ws(node.path);
var options = {};
if (node.tls) {
var tlsNode = RED.nodes.getNode(node.tls);
if (tlsNode) {
tlsNode.addTLSOptions(options);
}
}
var socket = new ws(node.path,options);
socket.setMaxListeners(0);
node.server = socket; // keep for closing
handleConnection(socket);

View File

@ -400,8 +400,9 @@
},
"listenon": "Listen on",
"connectto": "Connect to",
"payload": "Send/Receive payload",
"message": "Send/Receive entire message",
"sendrec": "Send/Receive",
"payload": "payload",
"message": "entire message",
"tip": {
"path1": "By default, <code>payload</code> will contain the data to be sent over, or received from a websocket. The listener can be configured to send or receive the entire message object as a JSON formatted string.",
"path2": "This path will be relative to ",