@node-red/nodes 2.1.4 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/LICENSE +1 -1
  2. package/core/common/20-inject.html +4 -4
  3. package/core/common/20-inject.js +2 -8
  4. package/core/function/10-function.html +6 -4
  5. package/core/function/10-function.js +5 -2
  6. package/core/function/89-delay.html +2 -1
  7. package/core/function/90-exec.js +3 -3
  8. package/core/function/rbe.js +1 -1
  9. package/core/network/10-mqtt.js +11 -5
  10. package/core/network/21-httprequest.js +6 -4
  11. package/core/network/22-websocket.html +6 -2
  12. package/core/network/22-websocket.js +22 -14
  13. package/core/network/31-tcpin.html +126 -20
  14. package/core/network/31-tcpin.js +162 -29
  15. package/core/parsers/70-JSON.js +5 -1
  16. package/core/storage/10-file.js +1 -3
  17. package/examples/common/link/03 - Link call.json +156 -0
  18. package/examples/storage/{file/01 - Write string to a file.json → read file/01 - Read string from a file.json } +22 -22
  19. package/examples/storage/{file-in → read file}/02 - Read data in specified encoding.json +23 -22
  20. package/examples/storage/{file-in → read file}/03 - Read data breaking lines into messages.json +25 -25
  21. package/examples/storage/{file-in → read file}/04 - Create a message stream.json +37 -37
  22. package/examples/storage/{file-in/01 - Read string from a file.json → write file/01 - Write string to a file.json } +15 -15
  23. package/examples/storage/{file → write file}/02 - Write string to a file specified by property.json +22 -22
  24. package/examples/storage/{file → write file}/03 - Delete a file.json +16 -16
  25. package/examples/storage/{file → write file}/04 - Specify encoding of written data.json +23 -23
  26. package/locales/de/messages.json +2 -1
  27. package/locales/en-US/function/80-template.html +1 -1
  28. package/locales/en-US/function/89-delay.html +1 -1
  29. package/locales/en-US/function/rbe.html +2 -2
  30. package/locales/en-US/messages.json +10 -6
  31. package/locales/en-US/network/10-mqtt.html +1 -1
  32. package/locales/en-US/network/21-httprequest.html +1 -1
  33. package/locales/en-US/sequence/17-split.html +1 -1
  34. package/locales/ja/function/80-template.html +2 -0
  35. package/locales/ja/function/89-delay.html +5 -2
  36. package/locales/ja/function/rbe.html +1 -1
  37. package/locales/ja/messages.json +9 -4
  38. package/locales/ja/network/10-mqtt.html +65 -4
  39. package/locales/ja/parsers/70-CSV.html +1 -1
  40. package/locales/ja/sequence/17-split.html +5 -2
  41. package/locales/ko/messages.json +2 -1
  42. package/locales/ru/messages.json +2 -1
  43. package/locales/zh-CN/messages.json +2 -1
  44. package/locales/zh-TW/messages.json +2 -1
  45. package/package.json +7 -7
package/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright JS Foundation and other contributors, http://js.foundation
1
+ Copyright OpenJS Foundation and other contributors, https://openjsf.org/
2
2
 
3
3
  Apache License
4
4
  Version 2.0, January 2004
@@ -234,7 +234,7 @@
234
234
  }
235
235
  } else if (v[i].vt === "jsonata") {
236
236
  try{jsonata(v[i].v);}catch(e){return false;}
237
- } else if ([i].vt === "json") {
237
+ } else if (v[i].vt === "json") {
238
238
  try{JSON.parse(v[i].v);}catch(e){return false;}
239
239
  }
240
240
  }
@@ -690,9 +690,9 @@
690
690
  this.topic = "";
691
691
  var result = getProps(items, true);
692
692
  this.props = result.props;
693
- if(result.payloadType) { this.payloadType = result.payloadType; };
694
- if(result.payload) { this.payload = result.payload; };
695
- if(result.topic) { this.topic = result.topic; };
693
+ if(result.hasOwnProperty('payloadType')) { this.payloadType = result.payloadType; };
694
+ if(result.hasOwnProperty('payload')) { this.payload = result.payload; };
695
+ if(result.hasOwnProperty('topic')) { this.topic = result.topic; };
696
696
  },
697
697
  button: {
698
698
  enabled: function() {
@@ -75,16 +75,12 @@ module.exports = function(RED) {
75
75
  node.repeaterSetup = function () {
76
76
  if (this.repeat && !isNaN(this.repeat) && this.repeat > 0) {
77
77
  this.repeat = this.repeat * 1000;
78
- if (RED.settings.verbose) {
79
- this.log(RED._("inject.repeat", this));
80
- }
78
+ this.debug(RED._("inject.repeat", this));
81
79
  this.interval_id = setInterval(function() {
82
80
  node.emit("input", {});
83
81
  }, this.repeat);
84
82
  } else if (this.crontab) {
85
- if (RED.settings.verbose) {
86
- this.log(RED._("inject.crontab", this));
87
- }
83
+ this.debug(RED._("inject.crontab", this));
88
84
  this.cronjob = scheduleTask(this.crontab,() => { node.emit("input", {})});
89
85
  }
90
86
  };
@@ -148,10 +144,8 @@ module.exports = function(RED) {
148
144
  }
149
145
  if (this.interval_id != null) {
150
146
  clearInterval(this.interval_id);
151
- if (RED.settings.verbose) { this.log(RED._("inject.stopped")); }
152
147
  } else if (this.cronjob != null) {
153
148
  this.cronjob.stop();
154
- if (RED.settings.verbose) { this.log(RED._("inject.stopped")); }
155
149
  delete this.cronjob;
156
150
  }
157
151
  };
@@ -91,21 +91,21 @@
91
91
  <div id="func-tab-init" style="display:none">
92
92
  <div class="form-row node-text-editor-row" style="position:relative">
93
93
  <div style="height: 250px; min-height:150px;" class="node-text-editor" id="node-input-init-editor" ></div>
94
- <div style="position: absolute; right:0; bottom: calc(100% - 20px); z-Index: 5;"><button id="node-init-expand-js" class="red-ui-button red-ui-button-small"><i class="fa fa-expand"></i></button></div>
94
+ <div style="position: absolute; right:0; bottom: calc(100% - 20px); z-Index: 10;"><button id="node-init-expand-js" class="red-ui-button red-ui-button-small"><i class="fa fa-expand"></i></button></div>
95
95
  </div>
96
96
  </div>
97
97
 
98
98
  <div id="func-tab-body" style="display:none">
99
99
  <div class="form-row node-text-editor-row" style="position:relative">
100
100
  <div style="height: 220px; min-height:150px;" class="node-text-editor" id="node-input-func-editor" ></div>
101
- <div style="position: absolute; right:0; bottom: calc(100% - 20px); z-Index: 5;"><button id="node-function-expand-js" class="red-ui-button red-ui-button-small"><i class="fa fa-expand"></i></button></div>
101
+ <div style="position: absolute; right:0; bottom: calc(100% - 20px); z-Index: 10;"><button id="node-function-expand-js" class="red-ui-button red-ui-button-small"><i class="fa fa-expand"></i></button></div>
102
102
  </div>
103
103
  </div>
104
104
 
105
105
  <div id="func-tab-finalize" style="display:none">
106
106
  <div class="form-row node-text-editor-row" style="position:relative">
107
107
  <div style="height: 250px; min-height:150px;" class="node-text-editor" id="node-input-finalize-editor" ></div>
108
- <div style="position: absolute; right:0; bottom: calc(100% - 20px); z-Index: 5;"><button id="node-finalize-expand-js" class="red-ui-button red-ui-button-small"><i class="fa fa-expand"></i></button></div>
108
+ <div style="position: absolute; right:0; bottom: calc(100% - 20px); z-Index: 10;"><button id="node-finalize-expand-js" class="red-ui-button red-ui-button-small"><i class="fa fa-expand"></i></button></div>
109
109
  </div>
110
110
  </div>
111
111
 
@@ -512,6 +512,7 @@
512
512
  return function(e) {
513
513
  e.preventDefault();
514
514
  var value = editor.getValue();
515
+ var extraLibs = that.libs || [];
515
516
  RED.editor.editJavaScript({
516
517
  value: value,
517
518
  width: "Infinity",
@@ -523,7 +524,8 @@
523
524
  setTimeout(function() {
524
525
  editor.focus();
525
526
  },300);
526
- }
527
+ },
528
+ extraLibs: extraLibs
527
529
  })
528
530
  }
529
531
  }
@@ -112,6 +112,7 @@ module.exports = function(RED) {
112
112
  "var node = {"+
113
113
  "id:__node__.id,"+
114
114
  "name:__node__.name,"+
115
+ "path:__node__.path,"+
115
116
  "outputCount:__node__.outputCount,"+
116
117
  "log:__node__.log,"+
117
118
  "error:__node__.error,"+
@@ -163,6 +164,7 @@ module.exports = function(RED) {
163
164
  __node__: {
164
165
  id: node.id,
165
166
  name: node.name,
167
+ path: node._path,
166
168
  outputCount: node.outputs,
167
169
  log: function() {
168
170
  node.log.apply(node, arguments);
@@ -234,8 +236,7 @@ module.exports = function(RED) {
234
236
  },
235
237
  env: {
236
238
  get: function(envVar) {
237
- var flow = node._flow;
238
- return flow.getSetting(envVar);
239
+ return RED.util.getSetting(node, envVar);
239
240
  }
240
241
  },
241
242
  setTimeout: function () {
@@ -345,6 +346,7 @@ module.exports = function(RED) {
345
346
  var node = {
346
347
  id:__node__.id,
347
348
  name:__node__.name,
349
+ path:__node__.path,
348
350
  outputCount:__node__.outputCount,
349
351
  log:__node__.log,
350
352
  error:__node__.error,
@@ -367,6 +369,7 @@ module.exports = function(RED) {
367
369
  var node = {
368
370
  id:__node__.id,
369
371
  name:__node__.name,
372
+ path:__node__.path,
370
373
  outputCount:__node__.outputCount,
371
374
  log:__node__.log,
372
375
  error:__node__.error,
@@ -114,7 +114,8 @@
114
114
  timeout: {value:"5", required:true, validate:function(v) { return RED.validators.number(v) && (v >= 0); }},
115
115
  timeoutUnits: {value:"seconds"},
116
116
  rate: {value:"1", required:true, validate:function(v) { return RED.validators.number(v) && (v >= 0); }},
117
- nbRateUnits: {value:"1", required:false, validate:RED.validators.regex(/\d+|/)},
117
+ nbRateUnits: {value:"1", required:false,
118
+ validate:function(v) { return RED.validators.number(v) && (v >= 0); }},
118
119
  rateUnits: {value: "second"},
119
120
  randomFirst: {value:"1", required:true, validate:function(v) { return RED.validators.number(v) && (v >= 0); }},
120
121
  randomLast: {value:"5", required:true, validate:function(v) { return RED.validators.number(v) && (v >= 0); }},
@@ -86,7 +86,7 @@ module.exports = function(RED) {
86
86
  });
87
87
  var cmd = arg.shift();
88
88
  /* istanbul ignore else */
89
- if (RED.settings.verbose) { node.log(cmd+" ["+arg+"]"); }
89
+ node.debug(cmd+" ["+arg+"]");
90
90
  child = spawn(cmd,arg,node.spawnOpt);
91
91
  node.status({fill:"blue",shape:"dot",text:"pid:"+child.pid});
92
92
  var unknownCommand = (child.pid === undefined);
@@ -136,7 +136,7 @@ module.exports = function(RED) {
136
136
  }
137
137
  else {
138
138
  /* istanbul ignore else */
139
- if (RED.settings.verbose) { node.log(arg); }
139
+ node.debug(arg);
140
140
  child = exec(arg, node.execOpt, function (error, stdout, stderr) {
141
141
  var msg2, msg3;
142
142
  delete msg.payload;
@@ -155,7 +155,7 @@ module.exports = function(RED) {
155
155
  if (error.signal) { msg3.payload.signal = error.signal; }
156
156
  if (error.code === null) { node.status({fill:"red",shape:"dot",text:"killed"}); }
157
157
  else { node.status({fill:"red",shape:"dot",text:"error:"+error.code}); }
158
- if (RED.settings.verbose) { node.log('error:' + error); }
158
+ node.debug('error:' + error);
159
159
  }
160
160
  else if (node.oldrc === "false") {
161
161
  msg3 = RED.util.cloneMessage(msg);
@@ -58,7 +58,7 @@ module.exports = function(RED) {
58
58
  else {
59
59
  var n = parseFloat(value);
60
60
  if (!isNaN(n)) {
61
- if ((typeof node.previous[t] === 'undefined') && (this.func === "narrowband")) {
61
+ if ((typeof node.previous[t] === 'undefined') && (this.func === "narrowband" || this.func === "narrowbandEq")) {
62
62
  if (node.start === '') { node.previous[t] = n; }
63
63
  else { node.previous[t] = node.start; }
64
64
  }
@@ -288,7 +288,7 @@ module.exports = function(RED) {
288
288
  //TODO: delete msg.responseTopic - to prevent it being resent?
289
289
  }
290
290
  }
291
- topicOK = topicOK && !/[\+#]/.test(msg.topic);
291
+ topicOK = topicOK && !/[\+#\b\f\n\r\t\v\0]/.test(msg.topic);
292
292
 
293
293
  if (topicOK) {
294
294
  node.brokerConn.publish(msg, done); // send the message
@@ -730,12 +730,18 @@ module.exports = function(RED) {
730
730
  node.client.on("reconnect", function() {
731
731
  setStatusConnecting(node, true);
732
732
  });
733
- //TODO: what to do with this event? Anything? Necessary?
733
+ //Broker Disconnect - V5 event
734
734
  node.client.on("disconnect", function(packet) {
735
735
  //Emitted after receiving disconnect packet from broker. MQTT 5.0 feature.
736
- var rc = packet && packet.properties && packet.properties.reasonString;
737
- var rc = packet && packet.properties && packet.reasonCode;
738
- //TODO: If keeping this event, do we use these? log these?
736
+ const rc = (packet && packet.properties && packet.reasonCode) || packet.reasonCode;
737
+ const rs = packet && packet.properties && packet.properties.reasonString || "";
738
+ const details = {
739
+ broker: (node.clientid?node.clientid+"@":"")+node.brokerurl,
740
+ reasonCode: rc,
741
+ reasonString: rs
742
+ }
743
+ node.log(RED._("mqtt.state.broker-disconnected", details));
744
+ setStatusDisconnected(node, true);
739
745
  });
740
746
  // Register disconnect handlers
741
747
  node.client.on('close', function () {
@@ -264,7 +264,7 @@ in your Node-RED user directory (${RED.settings.userDir}).
264
264
  if (opts.headers.hasOwnProperty('cookie')) {
265
265
  var cookies = cookie.parse(opts.headers.cookie, {decode:String});
266
266
  for (var name in cookies) {
267
- opts.cookieJar.setCookie(cookie.serialize(name, cookies[name], {encode:String}), url, {ignoreError: true});
267
+ opts.cookieJar.setCookieSync(cookie.serialize(name, cookies[name], {encode:String}), url, {ignoreError: true});
268
268
  }
269
269
  delete opts.headers.cookie;
270
270
  }
@@ -277,13 +277,13 @@ in your Node-RED user directory (${RED.settings.userDir}).
277
277
  } else if (typeof msg.cookies[name] === 'object') {
278
278
  if(msg.cookies[name].encode === false){
279
279
  // If the encode option is false, the value is not encoded.
280
- opts.cookieJar.setCookie(cookie.serialize(name, msg.cookies[name].value, {encode: String}), url, {ignoreError: true});
280
+ opts.cookieJar.setCookieSync(cookie.serialize(name, msg.cookies[name].value, {encode: String}), url, {ignoreError: true});
281
281
  } else {
282
282
  // The value is encoded by encodeURIComponent().
283
- opts.cookieJar.setCookie(cookie.serialize(name, msg.cookies[name].value), url, {ignoreError: true});
283
+ opts.cookieJar.setCookieSync(cookie.serialize(name, msg.cookies[name].value), url, {ignoreError: true});
284
284
  }
285
285
  } else {
286
- opts.cookieJar.setCookie(cookie.serialize(name, msg.cookies[name]), url, {ignoreError: true});
286
+ opts.cookieJar.setCookieSync(cookie.serialize(name, msg.cookies[name]), url, {ignoreError: true});
287
287
  }
288
288
  }
289
289
  }
@@ -302,6 +302,8 @@ in your Node-RED user directory (${RED.settings.userDir}).
302
302
  // var cred = ""
303
303
  if (this.credentials.user || this.credentials.password) {
304
304
  // cred = `${this.credentials.user}:${this.credentials.password}`;
305
+ if (this.credentials.user === undefined) { this.credentials.user = ""}
306
+ if (this.credentials.password === undefined) { this.credentials.password = ""}
305
307
  opts.headers.Authorization = "Basic " + Buffer.from(`${this.credentials.user}:${this.credentials.password}`).toString("base64");
306
308
  }
307
309
  // build own basic auth header
@@ -177,7 +177,8 @@
177
177
  path: {value:"",required:true,validate:RED.validators.regex(/^((?!\/debug\/ws).)*$/)},
178
178
  tls: {type:"tls-config",required: false},
179
179
  wholemsg: {value:"false"},
180
- hb: {value: "", validate: RED.validators.number(/*blank allowed*/true) }
180
+ hb: {value: "", validate: RED.validators.number(/*blank allowed*/true) },
181
+ subprotocol: {value:"",required: false}
181
182
  },
182
183
  inputs:0,
183
184
  outputs:0,
@@ -265,7 +266,10 @@
265
266
  <label for="node-config-input-tls" data-i18n="httpin.tls-config"></label>
266
267
  <input type="text" id="node-config-input-tls">
267
268
  </div>
268
-
269
+ <div class="form-row">
270
+ <label for="node-config-input-subprotocol"><i class="fa fa-tag"></i> <span data-i18n="websocket.label.subprotocol"></span></label>
271
+ <input type="text" id="node-config-input-subprotocol">
272
+ </div>
269
273
  <div class="form-row">
270
274
  <label for="node-config-input-wholemsg" data-i18n="websocket.sendrec"></label>
271
275
  <select type="text" id="node-config-input-wholemsg" style="width: 70%;">
@@ -46,6 +46,12 @@ module.exports = function(RED) {
46
46
 
47
47
  // Store local copies of the node configuration (as defined in the .html)
48
48
  node.path = n.path;
49
+ if (typeof n.subprotocol === "string") {
50
+ // Split the string on comma and trim each result
51
+ node.subprotocol = n.subprotocol.split(",").map(v => v.trim())
52
+ } else {
53
+ node.subprotocol = [];
54
+ }
49
55
  node.wholemsg = (n.wholemsg === "true");
50
56
 
51
57
  node._inputNodes = []; // collection of nodes that want to receive events
@@ -92,7 +98,7 @@ module.exports = function(RED) {
92
98
  tlsNode.addTLSOptions(options);
93
99
  }
94
100
  }
95
- var socket = new ws(node.path,options);
101
+ var socket = new ws(node.path,node.subprotocol,options);
96
102
  socket.setMaxListeners(0);
97
103
  node.server = socket; // keep for closing
98
104
  handleConnection(socket);
@@ -105,22 +111,24 @@ module.exports = function(RED) {
105
111
  if (node.isServer) {
106
112
  node._clients[id] = socket;
107
113
  node.emit('opened',{count:Object.keys(node._clients).length,id:id});
108
- } else {
109
- if (node.heartbeat) {
110
- node.heartbeatInterval = setInterval(function() {
111
- if (socket.nrPendingHeartbeat) {
112
- // No pong received
113
- socket.terminate();
114
- socket.nrErrorHandler(new Error("timeout"));
115
- return;
116
- }
117
- socket.nrPendingHeartbeat = true;
118
- socket.ping();
119
- },node.heartbeat);
120
- }
121
114
  }
122
115
  socket.on('open',function() {
123
116
  if (!node.isServer) {
117
+ if (node.heartbeat) {
118
+ clearInterval(node.heartbeatInterval);
119
+ node.heartbeatInterval = setInterval(function() {
120
+ if (socket.nrPendingHeartbeat) {
121
+ // No pong received
122
+ socket.terminate();
123
+ socket.nrErrorHandler(new Error("timeout"));
124
+ return;
125
+ }
126
+ socket.nrPendingHeartbeat = true;
127
+ try {
128
+ socket.ping();
129
+ } catch(err) {}
130
+ },node.heartbeat);
131
+ }
124
132
  node.emit('opened',{count:'',id:id});
125
133
  }
126
134
  });
@@ -23,9 +23,17 @@
23
23
  </select>
24
24
  <span data-i18n="tcpin.label.port"></span> <input type="text" id="node-input-port" style="width:65px">
25
25
  </div>
26
- <div class="form-row hidden" id="node-input-host-row" style="padding-left: 110px;">
26
+ <div class="form-row hidden" id="node-input-host-row" style="padding-left:110px;">
27
27
  <span data-i18n="tcpin.label.host"></span> <input type="text" id="node-input-host" placeholder="localhost" style="width: 60%;">
28
28
  </div>
29
+ <div class="form-row" id="node-input-tls-enable">
30
+ <label> </label>
31
+ <input type="checkbox" id="node-input-usetls" style="display: inline-block; width:auto; vertical-align:top;">
32
+ <label for="node-input-usetls" style="width:auto" data-i18n="httpin.use-tls"></label>
33
+ <div id="node-row-tls" class="hide">
34
+ <label style="width:auto; margin-left:20px; margin-right:10px;" for="node-input-tls"><span data-i18n="httpin.tls-config"></span></label><input type="text" style="width: 300px" id="node-input-tls">
35
+ </div>
36
+ </div>
29
37
 
30
38
  <div class="form-row">
31
39
  <label><i class="fa fa-sign-out"></i> <span data-i18n="tcpin.label.output"></span></label>
@@ -42,7 +50,7 @@
42
50
  </div>
43
51
 
44
52
  <div id="node-row-newline" class="form-row hidden" style="padding-left:110px;">
45
- <span data-i18n="tcpin.label.delimited"></span> <input type="text" id="node-input-newline" style="width:110px;">
53
+ <span data-i18n="tcpin.label.delimited"></span> <input type="text" id="node-input-newline" style="width:110px;" data-i18n="[placeholder]tcpin.label.optional">
46
54
  </div>
47
55
 
48
56
  <div class="form-row">
@@ -58,17 +66,18 @@
58
66
  <script type="text/javascript">
59
67
  RED.nodes.registerType('tcp in',{
60
68
  category: 'network',
61
- color:"Silver",
69
+ color: "Silver",
62
70
  defaults: {
63
71
  name: {value:""},
64
- server: {value:"server",required:true},
65
- host: {value:"",validate:function(v) { return (this.server == "server")||v.length > 0;} },
66
- port: {value:"",required:true,validate:RED.validators.number()},
72
+ server: {value:"server", required:true},
73
+ host: {value:"", validate:function(v) { return (this.server == "server")||v.length > 0;} },
74
+ port: {value:"", required:true, validate:RED.validators.number()},
67
75
  datamode:{value:"stream"},
68
76
  datatype:{value:"buffer"},
69
77
  newline:{value:""},
70
78
  topic: {value:""},
71
- base64: {/*deprecated*/ value:false,required:true}
79
+ base64: {/*deprecated*/ value:false, required:true},
80
+ tls: {type:"tls-config", value:'', required:false}
72
81
  },
73
82
  inputs:0,
74
83
  outputs:1,
@@ -77,7 +86,7 @@
77
86
  return this.name || "tcp:"+(this.host?this.host+":":"")+this.port;
78
87
  },
79
88
  labelStyle: function() {
80
- return this.name?"node_label_italic":"";
89
+ return this.name ? "node_label_italic" : "";
81
90
  },
82
91
  oneditprepare: function() {
83
92
  var updateOptions = function() {
@@ -103,6 +112,27 @@
103
112
  $("#node-input-server").change(updateOptions);
104
113
  $("#node-input-datatype").change(updateOptions);
105
114
  $("#node-input-datamode").change(updateOptions);
115
+ function updateTLSOptions() {
116
+ if ($("#node-input-usetls").is(':checked')) {
117
+ $("#node-row-tls").show();
118
+ } else {
119
+ $("#node-row-tls").hide();
120
+ }
121
+ }
122
+ if (this.tls) {
123
+ $('#node-input-usetls').prop('checked', true);
124
+ } else {
125
+ $('#node-input-usetls').prop('checked', false);
126
+ }
127
+ updateTLSOptions();
128
+ $("#node-input-usetls").on("click",function() {
129
+ updateTLSOptions();
130
+ });
131
+ },
132
+ oneditsave: function() {
133
+ if (!$("#node-input-usetls").is(':checked')) {
134
+ $("#node-input-tls").val("_ADD_");
135
+ }
106
136
  }
107
137
  });
108
138
  </script>
@@ -123,6 +153,15 @@
123
153
  <span data-i18n="tcpin.label.host"></span> <input type="text" id="node-input-host" style="width: 60%;">
124
154
  </div>
125
155
 
156
+ <div class="form-row" id="node-input-tls-enable">
157
+ <label> </label>
158
+ <input type="checkbox" id="node-input-usetls" style="display: inline-block; width: auto; vertical-align: top;">
159
+ <label for="node-input-usetls" style="width: auto" data-i18n="httpin.use-tls"></label>
160
+ <div id="node-row-tls" class="hide">
161
+ <label style="width: auto; margin-left: 20px; margin-right: 10px;" for="node-input-tls"><span data-i18n="httpin.tls-config"></span></label><input type="text" style="width: 300px" id="node-input-tls">
162
+ </div>
163
+ </div>
164
+
126
165
  <div class="form-row hidden" id="node-input-end-row">
127
166
  <label>&nbsp;</label>
128
167
  <input type="checkbox" id="node-input-end" style="display: inline-block; width: auto; vertical-align: top;">
@@ -144,14 +183,15 @@
144
183
  <script type="text/javascript">
145
184
  RED.nodes.registerType('tcp out',{
146
185
  category: 'network',
147
- color:"Silver",
186
+ color: "Silver",
148
187
  defaults: {
188
+ name: {value:""},
149
189
  host: {value:"",validate:function(v) { return (this.beserver != "client")||v.length > 0;} },
150
190
  port: {value:"",validate:function(v) { return (this.beserver == "reply")||RED.validators.number()(v); } },
151
- beserver: {value:"client",required:true},
152
- base64: {value:false,required:true},
153
- end: {value:false,required:true},
154
- name: {value:""}
191
+ beserver: {value:"client", required:true},
192
+ base64: {value:false, required:true},
193
+ end: {value:false, required:true},
194
+ tls: {type:"tls-config", value:'', required:false}
155
195
  },
156
196
  inputs:1,
157
197
  outputs:0,
@@ -170,18 +210,42 @@
170
210
  $("#node-input-port-row").hide();
171
211
  $("#node-input-host-row").hide();
172
212
  $("#node-input-end-row").hide();
213
+ $("#node-input-tls-enable").hide();
173
214
  } else if (sockettype == "client"){
174
215
  $("#node-input-port-row").show();
175
216
  $("#node-input-host-row").show();
176
217
  $("#node-input-end-row").show();
218
+ $("#node-input-tls-enable").show();
177
219
  } else {
178
220
  $("#node-input-port-row").show();
179
221
  $("#node-input-host-row").hide();
180
222
  $("#node-input-end-row").show();
223
+ $("#node-input-tls-enable").show();
181
224
  }
182
225
  };
183
226
  updateOptions();
184
227
  $("#node-input-beserver").change(updateOptions);
228
+ function updateTLSOptions() {
229
+ if ($("#node-input-usetls").is(':checked')) {
230
+ $("#node-row-tls").show();
231
+ } else {
232
+ $("#node-row-tls").hide();
233
+ }
234
+ }
235
+ if (this.tls) {
236
+ $('#node-input-usetls').prop('checked', true);
237
+ } else {
238
+ $('#node-input-usetls').prop('checked', false);
239
+ }
240
+ updateTLSOptions();
241
+ $("#node-input-usetls").on("click",function() {
242
+ updateTLSOptions();
243
+ });
244
+ },
245
+ oneditsave: function() {
246
+ if (!$("#node-input-usetls").is(':checked')) {
247
+ $("#node-input-tls").val("_ADD_");
248
+ }
185
249
  }
186
250
  });
187
251
  </script>
@@ -194,15 +258,23 @@
194
258
  <span data-i18n="tcpin.label.port"></span>
195
259
  <input type="text" id="node-input-port" style="width:60px">
196
260
  </div>
261
+ <div class="form-row" id="node-input-tls-enable">
262
+ <label> </label>
263
+ <input type="checkbox" id="node-input-usetls" style="display: inline-block; width: auto; vertical-align: top;">
264
+ <label for="node-input-usetls" style="width: auto" data-i18n="httpin.use-tls"></label>
265
+ <div id="node-row-tls" class="hide">
266
+ <label style="width: auto; margin-left: 20px; margin-right: 10px;" for="node-input-tls"><span data-i18n="httpin.tls-config"></span></label><input type="text" style="width: 300px" id="node-input-tls">
267
+ </div>
268
+ </div>
197
269
  <div class="form-row">
198
- <label for="node-input-out"><i class="fa fa-sign-out"></i> <span data-i18n="tcpin.label.return"></span></label>
270
+ <label for="node-input-ret"><i class="fa fa-sign-out"></i> <span data-i18n="tcpin.label.return"></span></label>
199
271
  <select type="text" id="node-input-ret" style="width:54%;">
200
272
  <option value="buffer" data-i18n="tcpin.output.buffer"></option>
201
273
  <option value="string" data-i18n="tcpin.output.string"></option>
202
274
  </select>
203
275
  </div>
204
276
  <div class="form-row">
205
- <label for="node-input-out"> </label>
277
+ <label for="node-input-out"><i class="fa fa-sign-out fa-rotate-90"></i> <span data-i18n="tcpin.label.close"></span></label>
206
278
  <select type="text" id="node-input-out" style="width:54%;">
207
279
  <option value="time" data-i18n="tcpin.return.timeout"></option>
208
280
  <option value="char" data-i18n="tcpin.return.character"></option>
@@ -213,6 +285,9 @@
213
285
  <input type="text" id="node-input-splitc" style="width:50px;">
214
286
  <span id="node-units"></span>
215
287
  </div>
288
+ <div id="node-row-newline" class="form-row hidden" style="padding-left:162px;">
289
+ <span data-i18n="tcpin.label.delimited"></span> <input type="text" id="node-input-newline" style="width:110px;" data-i18n="[placeholder]tcpin.label.optional">
290
+ </div>
216
291
  <div class="form-row">
217
292
  <label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
218
293
  <input type="text" id="node-input-name" data-i18n="[placeholder]common.label.name">
@@ -222,14 +297,16 @@
222
297
  <script type="text/javascript">
223
298
  RED.nodes.registerType('tcp request',{
224
299
  category: 'network',
225
- color:"Silver",
300
+ color: "Silver",
226
301
  defaults: {
302
+ name: {value:""},
227
303
  server: {value:""},
228
- port: {value:"",validate:RED.validators.regex(/^(\d*|)$/)},
229
- out: {value:"time",required:true},
304
+ port: {value:"", validate:RED.validators.regex(/^(\d*|)$/)},
305
+ out: {value:"time", required:true},
230
306
  ret: {value:"buffer"},
231
- splitc: {value:"0",required:true},
232
- name: {value:""}
307
+ splitc: {value:"0", required:true},
308
+ newline: {value:""},
309
+ tls: {type:"tls-config", value:'', required:false}
233
310
  },
234
311
  inputs:1,
235
312
  outputs:1,
@@ -246,6 +323,14 @@
246
323
  $("#node-input-ret").val("buffer");
247
324
  this.ret = "buffer";
248
325
  }
326
+ $("#node-input-ret").on("change", function() {
327
+ if ($("#node-input-ret").val() === "string" && $("#node-input-out").val() === "sit") { $("#node-row-newline").show(); }
328
+ else { $("#node-row-newline").hide(); }
329
+ });
330
+ $("#node-input-out").on("change", function() {
331
+ if ($("#node-input-ret").val() === "string" && $("#node-input-out").val() === "sit") { $("#node-row-newline").show(); }
332
+ else { $("#node-row-newline").hide(); }
333
+ });
249
334
  $("#node-input-out").on('focus', function () { previous = this.value; }).on("change", function() {
250
335
  $("#node-input-splitc").show();
251
336
  if (previous === null) { previous = $("#node-input-out").val(); }
@@ -272,6 +357,27 @@
272
357
  $("#node-input-splitc").hide();
273
358
  }
274
359
  });
360
+ function updateTLSOptions() {
361
+ if ($("#node-input-usetls").is(':checked')) {
362
+ $("#node-row-tls").show();
363
+ } else {
364
+ $("#node-row-tls").hide();
365
+ }
366
+ }
367
+ if (this.tls) {
368
+ $('#node-input-usetls').prop('checked', true);
369
+ } else {
370
+ $('#node-input-usetls').prop('checked', false);
371
+ }
372
+ updateTLSOptions();
373
+ $("#node-input-usetls").on("click",function() {
374
+ updateTLSOptions();
375
+ });
376
+ },
377
+ oneditsave: function() {
378
+ if (!$("#node-input-usetls").is(':checked')) {
379
+ $("#node-input-tls").val("_ADD_");
380
+ }
275
381
  }
276
382
  });
277
383
  </script>