@node-red/nodes 5.0.0-beta.2 → 5.0.0-beta.3
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.
- package/core/common/lib/debug/debug-utils.js +37 -11
- package/core/function/89-delay.js +6 -3
- package/core/function/90-exec.js +17 -9
- package/core/network/10-mqtt.js +11 -6
- package/core/network/22-websocket.js +5 -1
- package/core/network/31-tcpin.js +152 -140
- package/core/network/32-udp.js +12 -8
- package/package.json +6 -6
|
@@ -45,11 +45,11 @@ RED.debug = (function() {
|
|
|
45
45
|
'<a id="red-ui-sidebar-debug-pause" class="red-ui-sidebar-header-button" href="#"><i class="fa fa-pause"></i></a>'+
|
|
46
46
|
'</span>'+
|
|
47
47
|
'<span class="button-group">'+
|
|
48
|
-
'<a id="red-ui-sidebar-debug-filter" style="padding-right:
|
|
48
|
+
'<a id="red-ui-sidebar-debug-filter" style="padding-right: 3px" class="red-ui-sidebar-header-button" href="#"><i class="fa fa-filter"></i> <span></span> <i style="padding-left: 5px;" class="fa fa-caret-down"></i></a>'+
|
|
49
49
|
'</span>'+
|
|
50
50
|
'<span class="button-group">'+
|
|
51
|
-
'<a id="red-ui-sidebar-debug-clear" style="border-right: none; padding-right:
|
|
52
|
-
'<a id="red-ui-sidebar-debug-clear-opts" style="padding:
|
|
51
|
+
'<a id="red-ui-sidebar-debug-clear" style="border-right: none; padding-right: 2px" class="red-ui-sidebar-header-button" href="#" data-clear-type="all"><i class="fa fa-trash"></i> <span>all</span></a>' +
|
|
52
|
+
'<a id="red-ui-sidebar-debug-clear-opts" style="padding: 3px; border-left: none;" class="red-ui-sidebar-header-button" href="#"><i class="fa fa-caret-down"></i></a>'+
|
|
53
53
|
'</span></div>').appendTo(content);
|
|
54
54
|
|
|
55
55
|
var footerToolbar = $('<div>'+
|
|
@@ -433,12 +433,28 @@ RED.debug = (function() {
|
|
|
433
433
|
if (o) { stack.push(o); }
|
|
434
434
|
if (!busy && (stack.length > 0)) {
|
|
435
435
|
busy = true;
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
436
|
+
const message = stack.shift()
|
|
437
|
+
// call any preDebugLog hooks, allowing them to modify the message or block it from being displayed
|
|
438
|
+
RED.hooks.trigger('debugPreProcessMessage', { message }).then(result => {
|
|
439
|
+
if (result === false) {
|
|
440
|
+
return false; // A hook returned false - halt processing of this message
|
|
441
|
+
}
|
|
442
|
+
return processDebugMessage(message);
|
|
443
|
+
}).then(processArtifacts => {
|
|
444
|
+
if (processArtifacts === false) {
|
|
445
|
+
return false; // A hook returned false - halt processing of this message
|
|
446
|
+
}
|
|
447
|
+
const { message, element, payload } = processArtifacts || {};
|
|
448
|
+
return RED.hooks.trigger('debugPostProcessMessage', { message, element, payload });
|
|
449
|
+
}).catch(err => {
|
|
450
|
+
console.error("Error in debug process message hooks", err);
|
|
451
|
+
}).finally(() => {
|
|
452
|
+
setTimeout(function() {
|
|
453
|
+
busy = false;
|
|
454
|
+
handleDebugMessage();
|
|
455
|
+
}, 15); // every 15mS = 66 times a second
|
|
456
|
+
if (stack.length > numMessages) { stack = stack.splice(-numMessages); }
|
|
457
|
+
})
|
|
442
458
|
}
|
|
443
459
|
} else {
|
|
444
460
|
debugPausedMessageCount++
|
|
@@ -564,10 +580,13 @@ RED.debug = (function() {
|
|
|
564
580
|
sourceId: sourceNode && sourceNode.id,
|
|
565
581
|
rootPath: path,
|
|
566
582
|
nodeSelector: config.messageSourceClick,
|
|
567
|
-
enablePinning: true
|
|
583
|
+
enablePinning: true,
|
|
584
|
+
tools: o.tools // permit preDebugLog hooks to add extra tools to the <debugMessage> element
|
|
568
585
|
});
|
|
569
586
|
// Do this in a separate step so the element functions aren't stripped
|
|
570
587
|
debugMessage.appendTo(el);
|
|
588
|
+
// add the meta row tools container, even if there are no tools, so that the postProcessDebugMessage hook can add tools
|
|
589
|
+
const tools = $('<span class="red-ui-debug-msg-tools button-group"></span>').appendTo(metaRow)
|
|
571
590
|
// NOTE: relying on function error to have a "type" that all other msgs don't
|
|
572
591
|
if (o.hasOwnProperty("type") && (o.type === "function")) {
|
|
573
592
|
var errorLvlType = 'error';
|
|
@@ -579,7 +598,6 @@ RED.debug = (function() {
|
|
|
579
598
|
msg.addClass('red-ui-debug-msg-level-' + errorLvl);
|
|
580
599
|
$('<span class="red-ui-debug-msg-topic">function : (' + errorLvlType + ')</span>').appendTo(metaRow);
|
|
581
600
|
} else {
|
|
582
|
-
var tools = $('<span class="red-ui-debug-msg-tools button-group"></span>').appendTo(metaRow);
|
|
583
601
|
var filterMessage = $('<button class="red-ui-button red-ui-button-small"><i class="fa fa-caret-down"></i></button>').appendTo(tools);
|
|
584
602
|
filterMessage.on("click", function(e) {
|
|
585
603
|
e.preventDefault();
|
|
@@ -635,6 +653,14 @@ RED.debug = (function() {
|
|
|
635
653
|
if (atBottom) {
|
|
636
654
|
messageList.scrollTop(sbc.scrollHeight);
|
|
637
655
|
}
|
|
656
|
+
|
|
657
|
+
// return artifacts to permit postProcessDebugMessage hooks to modify the message element, access the
|
|
658
|
+
// processed payload or otherwise modify the message after it has been generated.
|
|
659
|
+
return {
|
|
660
|
+
message: o, // original debug message object, useful for any hook that might have tagged additional info onto it
|
|
661
|
+
element: msg, // the top-level element for this debug message
|
|
662
|
+
payload // the reconstructed debug message
|
|
663
|
+
}
|
|
638
664
|
}
|
|
639
665
|
|
|
640
666
|
function clearMessageList(clearFilter, filteredOnly) {
|
|
@@ -164,7 +164,8 @@ module.exports = function(RED) {
|
|
|
164
164
|
if (node.pauseType === "delay") {
|
|
165
165
|
node.on("input", function(msg, send, done) {
|
|
166
166
|
var id = ourTimeout(function() {
|
|
167
|
-
node.idList.
|
|
167
|
+
var idx = node.idList.indexOf(id);
|
|
168
|
+
if (idx !== -1) { node.idList.splice(idx, 1); }
|
|
168
169
|
if (node.timeout > 1000) {
|
|
169
170
|
node.status({fill:"blue",shape:"dot",text:node.idList.length});
|
|
170
171
|
}
|
|
@@ -189,7 +190,8 @@ module.exports = function(RED) {
|
|
|
189
190
|
}
|
|
190
191
|
if (delayvar < 0) { delayvar = 0; }
|
|
191
192
|
var id = ourTimeout(function() {
|
|
192
|
-
node.idList.
|
|
193
|
+
var idx = node.idList.indexOf(id);
|
|
194
|
+
if (idx !== -1) { node.idList.splice(idx, 1); }
|
|
193
195
|
if (node.idList.length === 0) { node.status({}); }
|
|
194
196
|
send(msg);
|
|
195
197
|
if (delayvar >= 0) {
|
|
@@ -212,7 +214,8 @@ module.exports = function(RED) {
|
|
|
212
214
|
node.on("input", function(msg, send, done) {
|
|
213
215
|
var wait = node.randomFirst + (node.diff * Math.random());
|
|
214
216
|
var id = ourTimeout(function() {
|
|
215
|
-
node.idList.
|
|
217
|
+
var idx = node.idList.indexOf(id);
|
|
218
|
+
if (idx !== -1) { node.idList.splice(idx, 1); }
|
|
216
219
|
send(msg);
|
|
217
220
|
if (node.timeout >= 1000) {
|
|
218
221
|
node.status({fill:"blue",shape:"dot",text:node.idList.length});
|
package/core/function/90-exec.js
CHANGED
|
@@ -105,18 +105,26 @@ module.exports = function(RED) {
|
|
|
105
105
|
}
|
|
106
106
|
node.activeProcesses[child.pid] = child;
|
|
107
107
|
child.stdout.on('data', function (data) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
108
|
+
try {
|
|
109
|
+
if (node.activeProcesses.hasOwnProperty(child.pid) && node.activeProcesses[child.pid] !== null) {
|
|
110
|
+
// console.log('[exec] stdout: ' + data,child.pid);
|
|
111
|
+
if (isUtf8(data)) { msg.payload = data.toString(); }
|
|
112
|
+
else { msg.payload = data; }
|
|
113
|
+
nodeSend([RED.util.cloneMessage(msg),null,null]);
|
|
114
|
+
}
|
|
115
|
+
} catch (err) {
|
|
116
|
+
node.error(err.toString());
|
|
113
117
|
}
|
|
114
118
|
});
|
|
115
119
|
child.stderr.on('data', function (data) {
|
|
116
|
-
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
+
try {
|
|
121
|
+
if (node.activeProcesses.hasOwnProperty(child.pid) && node.activeProcesses[child.pid] !== null) {
|
|
122
|
+
if (isUtf8(data)) { msg.payload = data.toString(); }
|
|
123
|
+
else { msg.payload = data; }
|
|
124
|
+
nodeSend([null,RED.util.cloneMessage(msg),null]);
|
|
125
|
+
}
|
|
126
|
+
} catch (err) {
|
|
127
|
+
node.error(err.toString());
|
|
120
128
|
}
|
|
121
129
|
});
|
|
122
130
|
child.on('close', function (code,signal) {
|
package/core/network/10-mqtt.js
CHANGED
|
@@ -227,6 +227,7 @@ module.exports = function(RED) {
|
|
|
227
227
|
* Handle the payload / packet recieved in MQTT In and MQTT Sub nodes
|
|
228
228
|
*/
|
|
229
229
|
function subscriptionHandler(node, datatype ,topic, payload, packet) {
|
|
230
|
+
if (!packet) { packet = {}; }
|
|
230
231
|
const msg = {topic:topic, payload:null, qos:packet.qos, retain:packet.retain};
|
|
231
232
|
const v5 = (node && node.brokerConn)
|
|
232
233
|
? node.brokerConn.v5()
|
|
@@ -1074,12 +1075,16 @@ module.exports = function(RED) {
|
|
|
1074
1075
|
|
|
1075
1076
|
if (!subscription.handler) {
|
|
1076
1077
|
subscription.handler = function (mtopic, mpayload, mpacket) {
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1078
|
+
try {
|
|
1079
|
+
const sops = subscription.options ? subscription.options.properties : {}
|
|
1080
|
+
const pops = (mpacket && mpacket.properties) || {}
|
|
1081
|
+
if (subIdsAvailable && pops.subscriptionIdentifier && sops.subscriptionIdentifier && (pops.subscriptionIdentifier !== sops.subscriptionIdentifier)) {
|
|
1082
|
+
//do nothing as subscriptionIdentifier does not match
|
|
1083
|
+
} else if (matchTopic(topic, mtopic)) {
|
|
1084
|
+
subscription.callback && subscription.callback(mtopic, mpayload, mpacket)
|
|
1085
|
+
}
|
|
1086
|
+
} catch (err) {
|
|
1087
|
+
node.error("MQTT subscription handler error: " + err.toString());
|
|
1083
1088
|
}
|
|
1084
1089
|
}
|
|
1085
1090
|
}
|
|
@@ -297,7 +297,11 @@ module.exports = function(RED) {
|
|
|
297
297
|
}
|
|
298
298
|
msg._session = {type:"websocket",id:id};
|
|
299
299
|
for (var i = 0; i < this._inputNodes.length; i++) {
|
|
300
|
-
|
|
300
|
+
try {
|
|
301
|
+
this._inputNodes[i].send(msg);
|
|
302
|
+
} catch (err) {
|
|
303
|
+
this.error(RED._("websocket.errors.send-error") + " " + err.toString());
|
|
304
|
+
}
|
|
301
305
|
}
|
|
302
306
|
}
|
|
303
307
|
|
package/core/network/31-tcpin.js
CHANGED
|
@@ -127,32 +127,36 @@ module.exports = function(RED) {
|
|
|
127
127
|
connectionPool[id] = client;
|
|
128
128
|
|
|
129
129
|
client.on('data', function (data) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
130
|
+
try {
|
|
131
|
+
if (node.datatype != 'buffer') {
|
|
132
|
+
data = data.toString(node.datatype);
|
|
133
|
+
}
|
|
134
|
+
if (node.stream) {
|
|
135
|
+
var msg;
|
|
136
|
+
if ((node.datatype) === "utf8" && node.newline !== "") {
|
|
137
|
+
buffer = buffer+data;
|
|
138
|
+
var parts = buffer.split(node.newline);
|
|
139
|
+
for (var i = 0; i<parts.length-1; i+=1) {
|
|
140
|
+
msg = {topic:node.topic, payload:parts[i]};
|
|
141
|
+
if (node.trim == true) { msg.payload += node.newline; }
|
|
142
|
+
msg._session = {type:"tcp",id:id};
|
|
143
|
+
node.send(msg);
|
|
144
|
+
}
|
|
145
|
+
buffer = parts[parts.length-1];
|
|
146
|
+
} else {
|
|
147
|
+
msg = {topic:node.topic, payload:data};
|
|
141
148
|
msg._session = {type:"tcp",id:id};
|
|
142
149
|
node.send(msg);
|
|
143
150
|
}
|
|
144
|
-
buffer = parts[parts.length-1];
|
|
145
151
|
} else {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if ((typeof data) === "string") {
|
|
152
|
-
buffer = buffer+data;
|
|
153
|
-
} else {
|
|
154
|
-
buffer = Buffer.concat([buffer,data],buffer.length+data.length);
|
|
152
|
+
if ((typeof data) === "string") {
|
|
153
|
+
buffer = buffer+data;
|
|
154
|
+
} else {
|
|
155
|
+
buffer = Buffer.concat([buffer,data],buffer.length+data.length);
|
|
156
|
+
}
|
|
155
157
|
}
|
|
158
|
+
} catch (err) {
|
|
159
|
+
node.error(RED._("tcpin.errors.error",{error:err.toString()}));
|
|
156
160
|
}
|
|
157
161
|
});
|
|
158
162
|
client.on('end', function() {
|
|
@@ -222,35 +226,39 @@ module.exports = function(RED) {
|
|
|
222
226
|
|
|
223
227
|
var buffer = (node.datatype == 'buffer') ? Buffer.alloc(0) : "";
|
|
224
228
|
socket.on('data', function (data) {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
229
|
+
try {
|
|
230
|
+
if (node.datatype != 'buffer') {
|
|
231
|
+
data = data.toString(node.datatype);
|
|
232
|
+
}
|
|
233
|
+
if (node.stream) {
|
|
234
|
+
var msg;
|
|
235
|
+
if ((typeof data) === "string" && node.newline !== "") {
|
|
236
|
+
buffer = buffer+data;
|
|
237
|
+
var parts = buffer.split(node.newline);
|
|
238
|
+
for (var i = 0; i<parts.length-1; i+=1) {
|
|
239
|
+
msg = {topic:node.topic, payload:parts[i], ip:socket.remoteAddress, port:socket.remotePort};
|
|
240
|
+
if (node.trim == true) { msg.payload += node.newline; }
|
|
241
|
+
msg._session = {type:"tcp",id:id};
|
|
242
|
+
node.send(msg);
|
|
243
|
+
}
|
|
244
|
+
buffer = parts[parts.length-1];
|
|
245
|
+
} else {
|
|
246
|
+
msg = {topic:node.topic, payload:data, ip:socket.remoteAddress, port:socket.remotePort};
|
|
236
247
|
msg._session = {type:"tcp",id:id};
|
|
237
248
|
node.send(msg);
|
|
238
249
|
}
|
|
239
|
-
buffer = parts[parts.length-1];
|
|
240
|
-
} else {
|
|
241
|
-
msg = {topic:node.topic, payload:data, ip:socket.remoteAddress, port:socket.remotePort};
|
|
242
|
-
msg._session = {type:"tcp",id:id};
|
|
243
|
-
node.send(msg);
|
|
244
250
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
+
else {
|
|
252
|
+
if ((typeof data) === "string") {
|
|
253
|
+
buffer = buffer+data;
|
|
254
|
+
} else {
|
|
255
|
+
buffer = Buffer.concat([buffer,data],buffer.length+data.length);
|
|
256
|
+
}
|
|
257
|
+
fromi = socket.remoteAddress;
|
|
258
|
+
fromp = socket.remotePort;
|
|
251
259
|
}
|
|
252
|
-
|
|
253
|
-
|
|
260
|
+
} catch (err) {
|
|
261
|
+
node.error(RED._("tcpin.errors.error",{error:err.toString()}));
|
|
254
262
|
}
|
|
255
263
|
});
|
|
256
264
|
socket.on('end', function() {
|
|
@@ -678,117 +686,121 @@ module.exports = function(RED) {
|
|
|
678
686
|
}
|
|
679
687
|
var chunk = "";
|
|
680
688
|
clients[connection_id].client.on('data', function(data) {
|
|
681
|
-
|
|
682
|
-
if (
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
689
|
+
try {
|
|
690
|
+
if (node.out === "sit") { // if we are staying connected just send the buffer
|
|
691
|
+
if (clients[connection_id]) {
|
|
692
|
+
const msg = clients[connection_id].lastMsg || {};
|
|
693
|
+
msg.payload = RED.util.cloneMessage(data);
|
|
694
|
+
if (node.ret === "string") {
|
|
695
|
+
try {
|
|
696
|
+
if (node.newline && node.newline !== "" ) {
|
|
697
|
+
chunk += msg.payload.toString();
|
|
698
|
+
let parts = chunk.split(node.newline);
|
|
699
|
+
for (var p=0; p<parts.length-1; p+=1) {
|
|
700
|
+
let m = RED.util.cloneMessage(msg);
|
|
701
|
+
m.payload = parts[p];
|
|
702
|
+
if (node.trim == true) { m.payload += node.newline; }
|
|
703
|
+
nodeSend(m);
|
|
704
|
+
}
|
|
705
|
+
chunk = parts[parts.length-1];
|
|
706
|
+
}
|
|
707
|
+
else {
|
|
708
|
+
msg.payload = msg.payload.toString();
|
|
709
|
+
nodeSend(msg);
|
|
695
710
|
}
|
|
696
|
-
chunk = parts[parts.length-1];
|
|
697
|
-
}
|
|
698
|
-
else {
|
|
699
|
-
msg.payload = msg.payload.toString();
|
|
700
|
-
nodeSend(msg);
|
|
701
711
|
}
|
|
712
|
+
catch(e) { node.error(RED._("tcpin.errors.bad-string"), msg); }
|
|
702
713
|
}
|
|
703
|
-
|
|
714
|
+
else { nodeSend(msg); }
|
|
704
715
|
}
|
|
705
|
-
else { nodeSend(msg); }
|
|
706
716
|
}
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
if (node.out === "time") {
|
|
715
|
-
if (clients[connection_id]) {
|
|
716
|
-
// do the timer thing
|
|
717
|
-
if (clients[connection_id].timeout) {
|
|
718
|
-
i += 1;
|
|
719
|
-
buf[i] = data[j];
|
|
720
|
-
}
|
|
721
|
-
else {
|
|
722
|
-
clients[connection_id].timeout = setTimeout(function () {
|
|
723
|
-
if (clients[connection_id]) {
|
|
724
|
-
clients[connection_id].timeout = null;
|
|
725
|
-
const msg = clients[connection_id].lastMsg || {};
|
|
726
|
-
msg.payload = Buffer.alloc(i+1);
|
|
727
|
-
buf.copy(msg.payload,0,0,i+1);
|
|
728
|
-
if (node.ret === "string") {
|
|
729
|
-
try { msg.payload = msg.payload.toString(); }
|
|
730
|
-
catch(e) { node.error("Failed to create string", msg); }
|
|
731
|
-
}
|
|
732
|
-
nodeSend(msg);
|
|
733
|
-
if (clients[connection_id].client) {
|
|
734
|
-
node.status({});
|
|
735
|
-
clients[connection_id].client.destroy();
|
|
736
|
-
delete clients[connection_id];
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
}, node.splitc);
|
|
740
|
-
i = 0;
|
|
741
|
-
buf[0] = data[j];
|
|
742
|
-
}
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
// count bytes into a buffer...
|
|
746
|
-
else if (node.out == "count") {
|
|
747
|
-
buf[i] = data[j];
|
|
748
|
-
i += 1;
|
|
749
|
-
if ( i >= node.splitc) {
|
|
717
|
+
// else if (node.splitc === 0) {
|
|
718
|
+
// clients[connection_id].msg.payload = data;
|
|
719
|
+
// node.send(clients[connection_id].msg);
|
|
720
|
+
// }
|
|
721
|
+
else {
|
|
722
|
+
for (var j = 0; j < data.length; j++ ) {
|
|
723
|
+
if (node.out === "time") {
|
|
750
724
|
if (clients[connection_id]) {
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
try { msg.payload = msg.payload.toString(); }
|
|
756
|
-
catch(e) { node.error("Failed to create string", msg); }
|
|
725
|
+
// do the timer thing
|
|
726
|
+
if (clients[connection_id].timeout) {
|
|
727
|
+
i += 1;
|
|
728
|
+
buf[i] = data[j];
|
|
757
729
|
}
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
730
|
+
else {
|
|
731
|
+
clients[connection_id].timeout = setTimeout(function () {
|
|
732
|
+
if (clients[connection_id]) {
|
|
733
|
+
clients[connection_id].timeout = null;
|
|
734
|
+
const msg = clients[connection_id].lastMsg || {};
|
|
735
|
+
msg.payload = Buffer.alloc(i+1);
|
|
736
|
+
buf.copy(msg.payload,0,0,i+1);
|
|
737
|
+
if (node.ret === "string") {
|
|
738
|
+
try { msg.payload = msg.payload.toString(); }
|
|
739
|
+
catch(e) { node.error("Failed to create string", msg); }
|
|
740
|
+
}
|
|
741
|
+
nodeSend(msg);
|
|
742
|
+
if (clients[connection_id].client) {
|
|
743
|
+
node.status({});
|
|
744
|
+
clients[connection_id].client.destroy();
|
|
745
|
+
delete clients[connection_id];
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
}, node.splitc);
|
|
749
|
+
i = 0;
|
|
750
|
+
buf[0] = data[j];
|
|
763
751
|
}
|
|
764
|
-
i = 0;
|
|
765
752
|
}
|
|
766
753
|
}
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
754
|
+
// count bytes into a buffer...
|
|
755
|
+
else if (node.out == "count") {
|
|
756
|
+
buf[i] = data[j];
|
|
757
|
+
i += 1;
|
|
758
|
+
if ( i >= node.splitc) {
|
|
759
|
+
if (clients[connection_id]) {
|
|
760
|
+
const msg = clients[connection_id].lastMsg || {};
|
|
761
|
+
msg.payload = Buffer.alloc(i);
|
|
762
|
+
buf.copy(msg.payload,0,0,i);
|
|
763
|
+
if (node.ret === "string") {
|
|
764
|
+
try { msg.payload = msg.payload.toString(); }
|
|
765
|
+
catch(e) { node.error("Failed to create string", msg); }
|
|
766
|
+
}
|
|
767
|
+
nodeSend(msg);
|
|
768
|
+
if (clients[connection_id].client) {
|
|
769
|
+
node.status({});
|
|
770
|
+
clients[connection_id].client.destroy();
|
|
771
|
+
delete clients[connection_id];
|
|
772
|
+
}
|
|
773
|
+
i = 0;
|
|
780
774
|
}
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
// look for a char
|
|
778
|
+
else {
|
|
779
|
+
buf[i] = data[j];
|
|
780
|
+
i += 1;
|
|
781
|
+
if (data[j] == node.splitc) {
|
|
782
|
+
if (clients[connection_id]) {
|
|
783
|
+
const msg = clients[connection_id].lastMsg || {};
|
|
784
|
+
msg.payload = Buffer.alloc(i);
|
|
785
|
+
buf.copy(msg.payload,0,0,i);
|
|
786
|
+
if (node.ret === "string") {
|
|
787
|
+
try { msg.payload = msg.payload.toString(); }
|
|
788
|
+
catch(e) { node.error("Failed to create string", msg); }
|
|
789
|
+
}
|
|
790
|
+
nodeSend(msg);
|
|
791
|
+
if (clients[connection_id].client) {
|
|
792
|
+
node.status({});
|
|
793
|
+
clients[connection_id].client.destroy();
|
|
794
|
+
delete clients[connection_id];
|
|
795
|
+
}
|
|
796
|
+
i = 0;
|
|
786
797
|
}
|
|
787
|
-
i = 0;
|
|
788
798
|
}
|
|
789
799
|
}
|
|
790
800
|
}
|
|
791
801
|
}
|
|
802
|
+
} catch (err) {
|
|
803
|
+
node.error(RED._("tcpin.errors.error",{error:err.toString()}));
|
|
792
804
|
}
|
|
793
805
|
});
|
|
794
806
|
|
package/core/network/32-udp.js
CHANGED
|
@@ -98,15 +98,19 @@ module.exports = function(RED) {
|
|
|
98
98
|
});
|
|
99
99
|
|
|
100
100
|
server.on('message', function (message, remote) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
101
|
+
try {
|
|
102
|
+
var msg;
|
|
103
|
+
if (node.datatype =="base64") {
|
|
104
|
+
msg = { payload:message.toString('base64'), fromip:remote.address+':'+remote.port, ip:remote.address, port:remote.port };
|
|
105
|
+
} else if (node.datatype =="utf8") {
|
|
106
|
+
msg = { payload:message.toString('utf8'), fromip:remote.address+':'+remote.port, ip:remote.address, port:remote.port };
|
|
107
|
+
} else {
|
|
108
|
+
msg = { payload:message, fromip:remote.address+':'+remote.port, ip:remote.address, port:remote.port };
|
|
109
|
+
}
|
|
110
|
+
node.send(msg);
|
|
111
|
+
} catch (err) {
|
|
112
|
+
node.error(RED._("udp.errors.error",{error:err.toString()}));
|
|
108
113
|
}
|
|
109
|
-
node.send(msg);
|
|
110
114
|
});
|
|
111
115
|
|
|
112
116
|
server.on('listening', function () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-red/nodes",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.3",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
}
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"acorn": "8.
|
|
19
|
-
"acorn-walk": "8.3.
|
|
20
|
-
"ajv": "8.
|
|
18
|
+
"acorn": "8.16.0",
|
|
19
|
+
"acorn-walk": "8.3.5",
|
|
20
|
+
"ajv": "8.18.0",
|
|
21
21
|
"body-parser": "1.20.4",
|
|
22
22
|
"cheerio": "1.0.0-rc.10",
|
|
23
23
|
"content-type": "1.0.5",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
"is-utf8": "0.2.1",
|
|
36
36
|
"js-yaml": "4.1.1",
|
|
37
37
|
"media-typer": "1.1.0",
|
|
38
|
-
"mqtt": "5.
|
|
39
|
-
"multer": "2.
|
|
38
|
+
"mqtt": "5.15.0",
|
|
39
|
+
"multer": "2.1.1",
|
|
40
40
|
"mustache": "4.2.0",
|
|
41
41
|
"node-watch": "0.7.4",
|
|
42
42
|
"on-headers": "1.1.0",
|