@node-red/nodes 4.0.0-beta.3-1 → 4.0.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.
@@ -194,27 +194,46 @@
194
194
  nodeMap[node.links[i]].new = true;
195
195
  }
196
196
  }
197
- var n;
198
- for (var id in nodeMap) {
197
+
198
+ let editHistories = []
199
+ let n;
200
+ for (let id in nodeMap) {
199
201
  if (nodeMap.hasOwnProperty(id)) {
200
202
  n = RED.nodes.node(id);
201
203
  if (n) {
204
+ editHistories.push({
205
+ t:'edit',
206
+ node: n,
207
+ changes: {
208
+ links: [...n.links]
209
+ },
210
+ changed: n.changed
211
+ })
202
212
  if (nodeMap[id].old && !nodeMap[id].new) {
203
213
  // Removed id
204
214
  i = n.links.indexOf(node.id);
205
215
  if (i > -1) {
206
216
  n.links.splice(i,1);
217
+ n.changed = true
218
+ n.dirty = true
207
219
  }
208
220
  } else if (!nodeMap[id].old && nodeMap[id].new) {
209
221
  // Added id
210
222
  i = n.links.indexOf(id);
211
223
  if (i === -1) {
212
224
  n.links.push(node.id);
225
+ n.changed = true
226
+ n.dirty = true
213
227
  }
214
228
  }
215
229
  }
216
230
  }
217
231
  }
232
+ if (editHistories.length > 0) {
233
+ return {
234
+ history: editHistories
235
+ }
236
+ }
218
237
  }
219
238
 
220
239
  function onAdd() {
@@ -254,13 +273,14 @@
254
273
  onEditPrepare(this,"link out");
255
274
  },
256
275
  oneditsave: function() {
257
- onEditSave(this);
276
+ const result = onEditSave(this);
258
277
  // In case the name has changed, ensure any link call nodes on this
259
278
  // tab are redrawn with the updated name
260
279
  var localCallNodes = RED.nodes.filterNodes({z:RED.workspaces.active(), type:"link call"});
261
280
  localCallNodes.forEach(function(node) {
262
281
  node.dirty = true;
263
282
  });
283
+ return result
264
284
  },
265
285
  onadd: onAdd,
266
286
  oneditresize: resizeNodeList
@@ -329,7 +349,7 @@
329
349
  onEditPrepare(this,"link in");
330
350
  },
331
351
  oneditsave: function() {
332
- onEditSave(this);
352
+ return onEditSave(this);
333
353
  },
334
354
  oneditresize: resizeNodeList
335
355
  });
@@ -373,7 +393,7 @@
373
393
 
374
394
  },
375
395
  oneditsave: function() {
376
- onEditSave(this);
396
+ return onEditSave(this);
377
397
  },
378
398
  onadd: onAdd,
379
399
  oneditresize: resizeNodeList
@@ -25,19 +25,19 @@ module.exports = function(RED) {
25
25
  function sendResults(node,send,_msgid,msgs,cloneFirstMessage) {
26
26
  if (msgs == null) {
27
27
  return;
28
- } else if (!util.isArray(msgs)) {
28
+ } else if (!Array.isArray(msgs)) {
29
29
  msgs = [msgs];
30
30
  }
31
31
  var msgCount = 0;
32
32
  for (var m=0; m<msgs.length; m++) {
33
33
  if (msgs[m]) {
34
- if (!util.isArray(msgs[m])) {
34
+ if (!Array.isArray(msgs[m])) {
35
35
  msgs[m] = [msgs[m]];
36
36
  }
37
37
  for (var n=0; n < msgs[m].length; n++) {
38
38
  var msg = msgs[m][n];
39
39
  if (msg !== null && msg !== undefined) {
40
- if (typeof msg === 'object' && !Buffer.isBuffer(msg) && !util.isArray(msg)) {
40
+ if (typeof msg === 'object' && !Buffer.isBuffer(msg) && !Array.isArray(msg)) {
41
41
  if (msgCount === 0 && cloneFirstMessage !== false) {
42
42
  msgs[m][n] = RED.util.cloneMessage(msgs[m][n]);
43
43
  msg = msgs[m][n];
@@ -47,7 +47,7 @@ module.exports = function(RED) {
47
47
  } else {
48
48
  var type = typeof msg;
49
49
  if (type === 'object') {
50
- type = Buffer.isBuffer(msg)?'Buffer':(util.isArray(msg)?'Array':'Date');
50
+ type = Buffer.isBuffer(msg)?'Buffer':(Array.isArray(msg)?'Array':'Date');
51
51
  }
52
52
  node.error(RED._("function.error.non-message-returned",{ type: type }));
53
53
  }
@@ -16,6 +16,7 @@
16
16
 
17
17
  module.exports = function(RED) {
18
18
  "use strict";
19
+ const { getProxyForUrl } = require('./lib/proxyHelper');
19
20
  var mqtt = require("mqtt");
20
21
  var isUtf8 = require('is-utf8');
21
22
  var HttpsProxyAgent = require('https-proxy-agent');
@@ -617,17 +618,8 @@ module.exports = function(RED) {
617
618
  // Only for ws or wss, check if proxy env var for additional configuration
618
619
  if (node.brokerurl.indexOf("wss://") > -1 || node.brokerurl.indexOf("ws://") > -1) {
619
620
  // check if proxy is set in env
620
- let prox, noprox, noproxy;
621
- if (process.env.http_proxy) { prox = process.env.http_proxy; }
622
- if (process.env.HTTP_PROXY) { prox = process.env.HTTP_PROXY; }
623
- if (process.env.no_proxy) { noprox = process.env.no_proxy.split(","); }
624
- if (process.env.NO_PROXY) { noprox = process.env.NO_PROXY.split(","); }
625
- if (noprox) {
626
- for (var i = 0; i < noprox.length; i += 1) {
627
- if (node.brokerurl.indexOf(noprox[i].trim()) !== -1) { noproxy = true; }
628
- }
629
- }
630
- if (prox && !noproxy) {
621
+ const prox = getProxyForUrl(node.brokerurl, RED.settings.proxyOptions);
622
+ if (prox) {
631
623
  var parsedUrl = url.parse(node.brokerurl);
632
624
  var proxyOpts = url.parse(prox);
633
625
  // true for wss
@@ -16,6 +16,7 @@
16
16
 
17
17
  module.exports = async function(RED) {
18
18
  "use strict";
19
+ const { getProxyForUrl, parseUrl } = require('./lib/proxyHelper');
19
20
  const { got } = await import('got')
20
21
  const {CookieJar} = require("tough-cookie");
21
22
  const { HttpProxyAgent, HttpsProxyAgent } = require('hpagent');
@@ -101,18 +102,18 @@ in your Node-RED user directory (${RED.settings.userDir}).
101
102
 
102
103
  node.insecureHTTPParser = n.insecureHTTPParser
103
104
 
104
- var prox, noprox;
105
- if (process.env.http_proxy) { prox = process.env.http_proxy; }
106
- if (process.env.HTTP_PROXY) { prox = process.env.HTTP_PROXY; }
107
- if (process.env.no_proxy) { noprox = process.env.no_proxy.split(","); }
108
- if (process.env.NO_PROXY) { noprox = process.env.NO_PROXY.split(","); }
109
-
110
- var proxyConfig = null;
111
- if (n.proxy) {
112
- proxyConfig = RED.nodes.getNode(n.proxy);
113
- prox = proxyConfig.url;
114
- noprox = proxyConfig.noproxy;
105
+ let proxyConfig = n.proxy ? RED.nodes.getNode(n.proxy) || {} : null
106
+ const getProxy = (url) => {
107
+ const proxyOptions = Object.assign({}, RED.settings.proxyOptions);
108
+ if (n.proxy && proxyConfig) {
109
+ proxyOptions.env = {
110
+ no_proxy: (proxyConfig.noproxy || []).join(','),
111
+ http_proxy: (proxyConfig.url)
112
+ }
113
+ }
114
+ return getProxyForUrl(url, proxyOptions)
115
115
  }
116
+ let prox = getProxy(nodeUrl || '')
116
117
 
117
118
  let timingLog = false;
118
119
  if (RED.settings.hasOwnProperty("httpRequestTimingLog")) {
@@ -141,7 +142,15 @@ in your Node-RED user directory (${RED.settings.userDir}).
141
142
  });
142
143
  }
143
144
  }
144
-
145
+ /**
146
+ * @param {Object} headersObject
147
+ * @param {string} name
148
+ * @return {any} value
149
+ */
150
+ const getHeaderValue = (headersObject, name) => {
151
+ const asLowercase = name.toLowercase();
152
+ return headersObject[Object.keys(headersObject).find(k => k.toLowerCase() === asLowercase)];
153
+ }
145
154
  this.on("input",function(msg,nodeSend,nodeDone) {
146
155
  checkNodeAgentPatch();
147
156
  //reset redirectList on each request
@@ -177,7 +186,11 @@ in your Node-RED user directory (${RED.settings.userDir}).
177
186
  url = "http://"+url;
178
187
  }
179
188
  }
180
-
189
+ // before any parameters are appended to the `url`, lets check see if the proxy needs a refresh
190
+ let proxyUrl = prox; // The proxyUrl determined for `nodeUrl`
191
+ if(url !== nodeUrl) {
192
+ proxyUrl = getProxy(url)
193
+ }
181
194
  // The Request module used in Node-RED 1.x was tolerant of query strings that
182
195
  // were partially encoded. For example - "?a=hello%20there&b=20%"
183
196
  // The GOT module doesn't like that.
@@ -521,49 +534,43 @@ in your Node-RED user directory (${RED.settings.userDir}).
521
534
  opts.headers[clSet] = opts.headers['content-length'];
522
535
  delete opts.headers['content-length'];
523
536
  }
524
-
525
- var noproxy;
526
- if (noprox) {
527
- for (var i = 0; i < noprox.length; i += 1) {
528
- if (url.indexOf(noprox[i]) !== -1) { noproxy=true; }
529
- }
537
+ if (!opts.headers.hasOwnProperty('user-agent')) {
538
+ opts.headers['user-agent'] = 'Mozilla/5.0 (Node-RED)';
530
539
  }
531
- if (prox && !noproxy) {
532
- var match = prox.match(/^(https?:\/\/)?(.+)?:([0-9]+)?/i);
540
+ if (proxyUrl) {
541
+ const match = proxyUrl.match(/^(https?:\/\/)?(.+)?:([0-9]+)?/i);
533
542
  if (match) {
534
- let proxyAgent;
535
- let proxyURL = new URL(prox);
543
+ const proxyURL = parseUrl(proxyUrl)
536
544
  //set username/password to null to stop empty creds header
545
+ /** @type {import('hpagent').HttpProxyAgentOptions} */
537
546
  let proxyOptions = {
538
- proxy: {
539
- protocol: proxyURL.protocol,
540
- hostname: proxyURL.hostname,
541
- port: proxyURL.port,
542
- username: null,
543
- password: null
544
- },
547
+ proxy: proxyUrl,
548
+ scheduling: 'lifo',
545
549
  maxFreeSockets: 256,
546
550
  maxSockets: 256,
547
551
  keepAlive: true
548
552
  }
549
553
  if (proxyConfig && proxyConfig.credentials) {
550
- let proxyUsername = proxyConfig.credentials.username || '';
551
- let proxyPassword = proxyConfig.credentials.password || '';
554
+ const proxyUsername = proxyConfig.credentials.username || '';
555
+ const proxyPassword = proxyConfig.credentials.password || '';
552
556
  if (proxyUsername || proxyPassword) {
557
+ proxyOptions.proxy = proxyURL
553
558
  proxyOptions.proxy.username = proxyUsername;
554
559
  proxyOptions.proxy.password = proxyPassword;
555
560
  }
556
561
  } else if (proxyURL.username || proxyURL.password){
557
- proxyOptions.proxy.username = proxyURL.username;
558
- proxyOptions.proxy.password = proxyURL.password;
562
+ proxyOptions.proxy = proxyURL
563
+ // proxyOptions.proxy.username = proxyURL.username;
564
+ // proxyOptions.proxy.password = proxyURL.password;
559
565
  }
560
566
  //need both incase of http -> https redirect
561
567
  opts.agent = {
562
568
  http: new HttpProxyAgent(proxyOptions),
563
- https: new HttpsProxyAgent(proxyOptions)
564
- }
569
+ https: new HttpProxyAgent(proxyOptions)
570
+ };
571
+
565
572
  } else {
566
- node.warn("Bad proxy url: "+ prox);
573
+ node.warn("Bad proxy url: " + proxyUrl);
567
574
  }
568
575
  }
569
576
  if (useKeepAlive && !opts.agent) {
@@ -20,7 +20,7 @@ module.exports = function(RED) {
20
20
  var inspect = require("util").inspect;
21
21
  var url = require("url");
22
22
  var HttpsProxyAgent = require('https-proxy-agent');
23
-
23
+ const { getProxyForUrl } = require('./lib/proxyHelper');
24
24
 
25
25
  var serverUpgradeAdded = false;
26
26
  function handleServerUpgrade(request, socket, head) {
@@ -69,21 +69,9 @@ module.exports = function(RED) {
69
69
 
70
70
  function startconn() { // Connect to remote endpoint
71
71
  node.tout = null;
72
- var prox, noprox;
73
- if (process.env.http_proxy) { prox = process.env.http_proxy; }
74
- if (process.env.HTTP_PROXY) { prox = process.env.HTTP_PROXY; }
75
- if (process.env.no_proxy) { noprox = process.env.no_proxy.split(","); }
76
- if (process.env.NO_PROXY) { noprox = process.env.NO_PROXY.split(","); }
77
-
78
- var noproxy = false;
79
- if (noprox) {
80
- for (var i in noprox) {
81
- if (node.path.indexOf(noprox[i].trim()) !== -1) { noproxy=true; }
82
- }
83
- }
84
-
85
- var agent = undefined;
86
- if (prox && !noproxy) {
72
+ const prox = getProxyForUrl(node.brokerurl, RED.settings.proxyOptions);
73
+ let agent = undefined;
74
+ if (prox) {
87
75
  agent = new HttpsProxyAgent(prox);
88
76
  }
89
77
 
@@ -0,0 +1,219 @@
1
+ /*
2
+ The MIT License
3
+
4
+ Copyright (C) 2016-2018 Rob Wu <rob@robwu.nl>
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ this software and associated documentation files (the "Software"), to deal in
8
+ the Software without restriction, including without limitation the rights to
9
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
10
+ of the Software, and to permit persons to whom the Software is furnished to do
11
+ so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+ */
16
+
17
+ /*
18
+ This proxy helper is heavily based on the proxy helper from Rob Wu as detailed above.
19
+ It has been modified to work with the Node-RED runtime environment.
20
+ The license for the original code is reproduced above.
21
+ */
22
+
23
+
24
+ /**
25
+ * Parse a URL into its components.
26
+ * @param {String} url The URL to parse
27
+ * @returns {URL}
28
+ */
29
+ const parseUrl = (url) => {
30
+ let parsedUrl = {
31
+ protocol: null,
32
+ host: null,
33
+ port: null,
34
+ hostname: null,
35
+ query: null,
36
+ href: null
37
+ }
38
+ try {
39
+ if (!url) { return parsedUrl }
40
+ parsedUrl = new URL(url)
41
+ } catch (error) {
42
+ // dont throw error
43
+ }
44
+ return parsedUrl
45
+ }
46
+
47
+ const DEFAULT_PORTS = {
48
+ ftp: 21,
49
+ gopher: 70,
50
+ http: 80,
51
+ https: 443,
52
+ ws: 80,
53
+ wss: 443,
54
+ mqtt: 1880,
55
+ mqtts: 8883
56
+ }
57
+
58
+ const modeOverride = getEnv('NR_PROXY_MODE', {})
59
+
60
+ /**
61
+ * @typedef {Object} ProxyOptions
62
+ * @property {'strict'|'legacy'} [mode] - Legacy mode is for non-strict previous proxy determination logic (for node-red <= v3.1 compatibility) (default 'strict')
63
+ * @property {boolean} [favourUpperCase] - Favour UPPER_CASE *_PROXY env vars (default false)
64
+ * @property {boolean} [lowerCaseOnly] - Prevent UPPER_CASE *_PROXY env vars being used. (default false)
65
+ * @property {boolean} [excludeNpm] - Prevent npm_config_*_proxy env vars being used. (default false)
66
+ * @property {object} [env] - The environment object to use (defaults to process.env)
67
+ */
68
+
69
+ /**
70
+ * Get the proxy URL for a given URL.
71
+ * @param {string|URL} url - The URL, or the result from url.parse.
72
+ * @param {ProxyOptions} [options] - The options object (optional)
73
+ * @return {string} The URL of the proxy that should handle the request to the
74
+ * given URL. If no proxy is set, this will be an empty string.
75
+ */
76
+ function getProxyForUrl(url, options) {
77
+ url = url || ''
78
+ const defaultOptions = {
79
+ mode: 'strict',
80
+ lowerCaseOnly: false,
81
+ favourUpperCase: false,
82
+ excludeNpm: false,
83
+ }
84
+ options = Object.assign({}, defaultOptions, options)
85
+
86
+ if (modeOverride === 'legacy' || modeOverride === 'strict') {
87
+ options.mode = modeOverride
88
+ }
89
+
90
+ if (options.mode === 'legacy') {
91
+ return legacyGetProxyForUrl(url, options.env || process.env)
92
+ }
93
+
94
+ const parsedUrl = typeof url === 'string' ? parseUrl(url) : url || {}
95
+ let proto = parsedUrl.protocol
96
+ let hostname = parsedUrl.host
97
+ let port = parsedUrl.port
98
+ if (typeof hostname !== 'string' || !hostname || typeof proto !== 'string') {
99
+ return '' // Don't proxy URLs without a valid scheme or host.
100
+ }
101
+
102
+ proto = proto.split(':', 1)[0]
103
+ // Stripping ports in this way instead of using parsedUrl.hostname to make
104
+ // sure that the brackets around IPv6 addresses are kept.
105
+ hostname = hostname.replace(/:\d*$/, '')
106
+ port = parseInt(port) || DEFAULT_PORTS[proto] || 0
107
+ if (!shouldProxy(hostname, port, options)) {
108
+ return '' // Don't proxy URLs that match NO_PROXY.
109
+ }
110
+
111
+ let proxy =
112
+ getEnv('npm_config_' + proto + '_proxy', options) ||
113
+ getEnv(proto + '_proxy', options) ||
114
+ getEnv('npm_config_proxy', options) ||
115
+ getEnv('all_proxy', options)
116
+ if (proxy && proxy.indexOf('://') === -1) {
117
+ // Missing scheme in proxy, default to the requested URL's scheme.
118
+ proxy = proto + '://' + proxy
119
+ }
120
+ return proxy
121
+ }
122
+
123
+ /**
124
+ * Get the proxy URL for a given URL.
125
+ * For node-red < v3.1 or compatibility mode
126
+ * @param {string} url The URL to check for proxying
127
+ * @param {object} [env] The environment object to use (default process.env)
128
+ * @returns
129
+ */
130
+ function legacyGetProxyForUrl(url, env) {
131
+ env = env || process.env
132
+ let prox, noprox;
133
+ if (env.http_proxy) { prox = env.http_proxy; }
134
+ if (env.HTTP_PROXY) { prox = env.HTTP_PROXY; }
135
+ if (env.no_proxy) { noprox = env.no_proxy.split(","); }
136
+ if (env.NO_PROXY) { noprox = env.NO_PROXY.split(","); }
137
+
138
+ let noproxy = false;
139
+ if (noprox) {
140
+ for (let i in noprox) {
141
+ if (url.indexOf(noprox[i].trim()) !== -1) { noproxy=true; }
142
+ }
143
+ }
144
+ if (prox && !noproxy) {
145
+ return prox
146
+ }
147
+ return ""
148
+ }
149
+
150
+ /**
151
+ * Determines whether a given URL should be proxied.
152
+ *
153
+ * @param {string} hostname - The host name of the URL.
154
+ * @param {number} port - The effective port of the URL.
155
+ * @returns {boolean} Whether the given URL should be proxied.
156
+ * @private
157
+ */
158
+ function shouldProxy(hostname, port, options) {
159
+ const NO_PROXY =
160
+ (getEnv('npm_config_no_proxy', options) || getEnv('no_proxy', options)).toLowerCase()
161
+ if (!NO_PROXY) {
162
+ return true // Always proxy if NO_PROXY is not set.
163
+ }
164
+ if (NO_PROXY === '*') {
165
+ return false // Never proxy if wildcard is set.
166
+ }
167
+
168
+ return NO_PROXY.split(/[,\s]/).every(function (proxy) {
169
+ if (!proxy) {
170
+ return true // Skip zero-length hosts.
171
+ }
172
+ const parsedProxy = proxy.match(/^(.+):(\d+)$/)
173
+ let parsedProxyHostname = parsedProxy ? parsedProxy[1] : proxy
174
+ const parsedProxyPort = parsedProxy ? parseInt(parsedProxy[2]) : 0
175
+ if (parsedProxyPort && parsedProxyPort !== port) {
176
+ return true // Skip if ports don't match.
177
+ }
178
+
179
+ if (!/^[.*]/.test(parsedProxyHostname)) {
180
+ // No wildcards, so stop proxying if there is an exact match.
181
+ return hostname !== parsedProxyHostname
182
+ }
183
+
184
+ if (parsedProxyHostname.charAt(0) === '*') {
185
+ // Remove leading wildcard.
186
+ parsedProxyHostname = parsedProxyHostname.slice(1)
187
+ }
188
+ // Stop proxying if the hostname ends with the no_proxy host.
189
+ return !hostname.endsWith(parsedProxyHostname)
190
+ })
191
+ }
192
+
193
+ /**
194
+ * Get the value for an environment constiable.
195
+ *
196
+ * @param {string} key - The name of the environment constiable.
197
+ * @param {ProxyOptions} options - The name of the environment constiable.
198
+ * @return {string} The value of the environment constiable.
199
+ * @private
200
+ */
201
+ function getEnv(key, options) {
202
+ const env = (options && options.env) || process.env
203
+ if (options && options.excludeNpm === true) {
204
+ if (key.startsWith('npm_config_')) {
205
+ return ''
206
+ }
207
+ }
208
+ if (options && options.lowerCaseOnly === true) {
209
+ return env[key.toLowerCase()] || ''
210
+ } else if (options && options.favourUpperCase === true) {
211
+ return env[key.toUpperCase()] || env[key.toLowerCase()] || ''
212
+ }
213
+ return env[key.toLowerCase()] || env[key.toUpperCase()] || ''
214
+ }
215
+
216
+ module.exports = {
217
+ getProxyForUrl,
218
+ parseUrl
219
+ }
@@ -20,12 +20,26 @@
20
20
  <dt class="optional">delay <span class="property-type">number</span></dt>
21
21
  <dd>Legt die Verzögerung in Millisekunden fest, die auf die Nachricht angewendet werden soll.
22
22
  Zur Nutzung dieser Option muss <i>Verzög. mit msg.delay überschreibbar</i> aktiviert sein.</dd>
23
+ <dt class="optional">rate <span class="property-type">number</span></dt>
24
+ <dd>Setzt die Verzögerung in Millisekunden zwischen den Nachrichten. Diese Node überschreibt die
25
+ bestehende Verzögerung die in der Node konfiguration, wenn die empfangende Nachricht <code>msg.rate</code>
26
+ in Millisekunden enthält. Dies trifft nur zu, wenn in der Node konfiguriert ist, das empfangene
27
+ Nachrichten den konfigurierten Wert überschreiben können.</dd>
23
28
  <dt class="optional">reset</dt>
24
29
  <dd>Wenn bei der empfangenen Nachricht diese Eigenschaft auf einen beliebigen Wert gesetzt ist,
25
30
  werden alle im Node gepufferten Nachrichten gelöscht.</dd>
26
31
  <dt class="optional">flush</dt>
27
32
  <dd>Wenn bei der empfangenen Nachricht diese Eigenschaft auf einen beliebigen Wert gesetzt ist,
28
33
  werden alle im Node gepufferten Nachrichten sofort gesendet.</dd>
34
+ <dt class="optional">flush</dt>
35
+ <dd>Wenn bei der empfangenen Nachricht diese Eigenschaft auf einen numerischen Wert gesetzt ist,
36
+ wird diese Anzahl an Nachrichten sofort gesendet. Wenn ein anderer Typ gesetzt ist (z.B. Boolean),
37
+ werden alle in der Node gepufferten Nachrichten gesendet.</dd>
38
+ <dt class="optional">toFront</dt>
39
+ <dd>Wenn diese Eigenschaft im Ratenbegrenzungsmodus für die empfangene Nachricht auf den booleschen Wert
40
+ <code>true</code> gesetzt ist, Anschließend wird die Nachricht an den Anfang der Warteschlange verschoben
41
+ und als nächstes freigegeben. Dies kann in Kombination mit <code>msg.flush=1</code> verwendet werden, um sofort erneut zu senden.
42
+ </dd>
29
43
  </dl>
30
44
  <h3>Details</h3>
31
45
  <p>Wenn Verzögerung als Nachrichtenaktion eingestellt ist, kann die Verzögerungszeit ein fixer Wert,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@node-red/nodes",
3
- "version": "4.0.0-beta.3-1",
3
+ "version": "4.0.0",
4
4
  "license": "Apache-2.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -15,19 +15,19 @@
15
15
  }
16
16
  ],
17
17
  "dependencies": {
18
- "acorn": "8.8.2",
19
- "acorn-walk": "8.2.0",
20
- "ajv": "8.12.0",
18
+ "acorn": "8.11.3",
19
+ "acorn-walk": "8.3.2",
20
+ "ajv": "8.14.0",
21
21
  "body-parser": "1.20.2",
22
22
  "cheerio": "1.0.0-rc.10",
23
23
  "content-type": "1.0.5",
24
24
  "cookie-parser": "1.4.6",
25
- "cookie": "0.5.0",
25
+ "cookie": "0.6.0",
26
26
  "cors": "2.8.5",
27
27
  "cronosjs": "1.7.1",
28
28
  "denque": "2.1.0",
29
29
  "form-data": "4.0.0",
30
- "fs-extra": "11.1.1",
30
+ "fs-extra": "11.2.0",
31
31
  "got": "12.6.0",
32
32
  "hash-sum": "2.0.0",
33
33
  "hpagent": "1.2.0",
@@ -35,15 +35,15 @@
35
35
  "is-utf8": "0.2.1",
36
36
  "js-yaml": "4.1.0",
37
37
  "media-typer": "1.1.0",
38
- "mqtt": "4.3.7",
38
+ "mqtt": "5.7.0",
39
39
  "multer": "1.4.5-lts.1",
40
40
  "mustache": "4.2.0",
41
41
  "node-watch": "0.7.4",
42
42
  "on-headers": "1.0.2",
43
43
  "raw-body": "2.5.2",
44
- "tough-cookie": "4.1.3",
45
- "uuid": "9.0.0",
46
- "ws": "7.5.6",
44
+ "tough-cookie": "4.1.4",
45
+ "uuid": "9.0.1",
46
+ "ws": "7.5.10",
47
47
  "xml2js": "0.6.2",
48
48
  "iconv-lite": "0.6.3"
49
49
  }
@@ -1,257 +0,0 @@
1
- /**
2
- * Copyright JS Foundation and other contributors, http://js.foundation
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- **/
16
- var util = require("util");
17
- var mqtt = require("mqtt");
18
- var events = require("events");
19
-
20
- util.log("[warn] nodes/core/io/lib/mqtt.js is deprecated and will be removed in a future release of Node-RED. Please report this usage to the Node-RED mailing list.");
21
-
22
- //var inspect = require("util").inspect;
23
-
24
- //var Client = module.exports.Client = function(
25
-
26
- var port = 1883;
27
- var host = "localhost";
28
-
29
- function MQTTClient(port,host) {
30
- this.port = port||1883;
31
- this.host = host||"localhost";
32
- this.messageId = 1;
33
- this.pendingSubscriptions = {};
34
- this.inboundMessages = {};
35
- this.lastOutbound = (new Date()).getTime();
36
- this.lastInbound = (new Date()).getTime();
37
- this.connected = false;
38
-
39
- this._nextMessageId = function() {
40
- this.messageId += 1;
41
- if (this.messageId > 0xFFFF) {
42
- this.messageId = 1;
43
- }
44
- return this.messageId;
45
- }
46
- events.EventEmitter.call(this);
47
- }
48
- util.inherits(MQTTClient, events.EventEmitter);
49
-
50
- MQTTClient.prototype.connect = function(options) {
51
- if (!this.connected) {
52
- var self = this;
53
- options = options||{};
54
- self.options = options;
55
- self.options.keepalive = options.keepalive||15;
56
- self.options.clean = self.options.clean||true;
57
- self.options.protocolId = 'MQIsdp';
58
- self.options.protocolVersion = 3;
59
-
60
- self.client = mqtt.createConnection(this.port,this.host,function(err,client) {
61
- if (err) {
62
- self.connected = false;
63
- clearInterval(self.watchdog);
64
- self.connectionError = true;
65
- //util.log('[mqtt] ['+self.uid+'] connection error 1 : '+inspect(err));
66
- self.emit('connectionlost',err);
67
- return;
68
- }
69
- client.on('close',function(e) {
70
- //util.log('[mqtt] ['+self.uid+'] on close');
71
- clearInterval(self.watchdog);
72
- if (!self.connectionError) {
73
- if (self.connected) {
74
- self.connected = false;
75
- self.emit('connectionlost',e);
76
- } else {
77
- self.emit('disconnect');
78
- }
79
- }
80
- });
81
- client.on('error',function(e) {
82
- //util.log('[mqtt] ['+self.uid+'] on error : '+inspect(e));
83
- clearInterval(self.watchdog);
84
- if (self.connected) {
85
- self.connected = false;
86
- self.emit('connectionlost',e);
87
- }
88
- });
89
- client.on('connack',function(packet) {
90
- if (packet.returnCode === 0) {
91
- self.watchdog = setInterval(function(self) {
92
- var now = (new Date()).getTime();
93
-
94
- //util.log('[mqtt] ['+self.uid+'] watchdog '+inspect({connected:self.connected,connectionError:self.connectionError,pingOutstanding:self.pingOutstanding,now:now,lastOutbound:self.lastOutbound,lastInbound:self.lastInbound}));
95
-
96
- if (now - self.lastOutbound > self.options.keepalive*500 || now - self.lastInbound > self.options.keepalive*500) {
97
- if (self.pingOutstanding) {
98
- //util.log('[mqtt] ['+self.uid+'] watchdog pingOustanding - disconnect');
99
- try {
100
- self.client.disconnect();
101
- } catch (err) {
102
- }
103
- } else {
104
- //util.log('[mqtt] ['+self.uid+'] watchdog pinging');
105
- self.lastOutbound = (new Date()).getTime();
106
- self.lastInbound = (new Date()).getTime();
107
- self.pingOutstanding = true;
108
- self.client.pingreq();
109
- }
110
- }
111
-
112
- },self.options.keepalive*500,self);
113
- self.pingOutstanding = false;
114
- self.lastInbound = (new Date()).getTime()
115
- self.lastOutbound = (new Date()).getTime()
116
- self.connected = true;
117
- self.connectionError = false;
118
- self.emit('connect');
119
- } else {
120
- self.connected = false;
121
- self.emit('connectionlost');
122
- }
123
- });
124
- client.on('suback',function(packet) {
125
- self.lastInbound = (new Date()).getTime()
126
- var topic = self.pendingSubscriptions[packet.messageId];
127
- self.emit('subscribe',topic,packet.granted[0]);
128
- delete self.pendingSubscriptions[packet.messageId];
129
- });
130
- client.on('unsuback',function(packet) {
131
- self.lastInbound = (new Date()).getTime()
132
- var topic = self.pendingSubscriptions[packet.messageId];
133
- self.emit('unsubscribe',topic);
134
- delete self.pendingSubscriptions[packet.messageId];
135
- });
136
- client.on('publish',function(packet) {
137
- self.lastInbound = (new Date()).getTime();
138
- if (packet.qos < 2) {
139
- var p = packet;
140
- self.emit('message',p.topic,p.payload,p.qos,p.retain);
141
- } else {
142
- self.inboundMessages[packet.messageId] = packet;
143
- this.lastOutbound = (new Date()).getTime()
144
- self.client.pubrec(packet);
145
- }
146
- if (packet.qos == 1) {
147
- this.lastOutbound = (new Date()).getTime()
148
- self.client.puback(packet);
149
- }
150
- });
151
-
152
- client.on('pubrel',function(packet) {
153
- self.lastInbound = (new Date()).getTime()
154
- var p = self.inboundMessages[packet.messageId];
155
- if (p) {
156
- self.emit('message',p.topic,p.payload,p.qos,p.retain);
157
- delete self.inboundMessages[packet.messageId];
158
- }
159
- self.lastOutbound = (new Date()).getTime()
160
- self.client.pubcomp(packet);
161
- });
162
-
163
- client.on('puback',function(packet) {
164
- self.lastInbound = (new Date()).getTime()
165
- // outbound qos-1 complete
166
- });
167
-
168
- client.on('pubrec',function(packet) {
169
- self.lastInbound = (new Date()).getTime()
170
- self.lastOutbound = (new Date()).getTime()
171
- self.client.pubrel(packet);
172
- });
173
- client.on('pubcomp',function(packet) {
174
- self.lastInbound = (new Date()).getTime()
175
- // outbound qos-2 complete
176
- });
177
- client.on('pingresp',function(packet) {
178
- //util.log('[mqtt] ['+self.uid+'] received pingresp');
179
- self.lastInbound = (new Date()).getTime()
180
- self.pingOutstanding = false;
181
- });
182
-
183
- this.lastOutbound = (new Date()).getTime()
184
- this.connectionError = false;
185
- client.connect(self.options);
186
- });
187
- }
188
- }
189
-
190
- MQTTClient.prototype.subscribe = function(topic,qos) {
191
- var self = this;
192
- if (self.connected) {
193
- var options = {
194
- subscriptions:[{topic:topic,qos:qos}],
195
- messageId: self._nextMessageId()
196
- };
197
- this.pendingSubscriptions[options.messageId] = topic;
198
- this.lastOutbound = (new Date()).getTime();
199
- self.client.subscribe(options);
200
- self.client.setPacketEncoding('binary');
201
- }
202
- }
203
- MQTTClient.prototype.unsubscribe = function(topic) {
204
- var self = this;
205
- if (self.connected) {
206
- var options = {
207
- unsubscriptions:[topic],
208
- messageId: self._nextMessageId()
209
- };
210
- this.pendingSubscriptions[options.messageId] = topic;
211
- this.lastOutbound = (new Date()).getTime()
212
- self.client.unsubscribe(options);
213
- }
214
- }
215
-
216
- MQTTClient.prototype.publish = function(topic,payload,qos,retain) {
217
- var self = this;
218
- if (self.connected) {
219
-
220
- if (!Buffer.isBuffer(payload)) {
221
- if (typeof payload === "object") {
222
- payload = JSON.stringify(payload);
223
- } else if (typeof payload !== "string") {
224
- payload = ""+payload;
225
- }
226
- }
227
- var options = {
228
- topic: topic,
229
- payload: payload,
230
- qos: qos||0,
231
- retain:retain||false
232
- };
233
- if (options.qos !== 0) {
234
- options.messageId = self._nextMessageId();
235
- }
236
- this.lastOutbound = (new Date()).getTime()
237
- self.client.publish(options);
238
- }
239
- }
240
-
241
- MQTTClient.prototype.disconnect = function() {
242
- var self = this;
243
- if (this.connected) {
244
- this.connected = false;
245
- try {
246
- this.client.disconnect();
247
- } catch(err) {
248
- }
249
- }
250
- }
251
- MQTTClient.prototype.isConnected = function() {
252
- return this.connected;
253
- }
254
- module.exports.createClient = function(port,host) {
255
- var mqtt_client = new MQTTClient(port,host);
256
- return mqtt_client;
257
- }