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

TCP nodes- Add optional reattach delimiter to streaming strings

This commit is contained in:
Dave Conway-Jones 2022-02-25 15:56:13 +00:00
parent 0533c08438
commit 8c19daf949
No known key found for this signature in database
GPG Key ID: 88BA2B8A411BE9FF
3 changed files with 16 additions and 6 deletions

View File

@ -50,7 +50,8 @@
</div>
<div id="node-row-newline" class="form-row hidden" style="padding-left:110px;">
<span data-i18n="tcpin.label.delimited"></span> <input type="text" id="node-input-newline" style="width:110px;" data-i18n="[placeholder]tcpin.label.optional">
<span data-i18n="tcpin.label.delimited"></span> <input type="text" id="node-input-newline" style="width:110px;" data-i18n="[placeholder]tcpin.label.optional"><br/>
<input type="checkbox" id="node-input-trim" style="display:inline-block; width:auto; vertical-align:top;"> <span data-i18n="tcpin.label.reattach"></span>
</div>
<div class="form-row">
@ -76,6 +77,7 @@
datatype:{value:"buffer"},
newline:{value:""},
topic: {value:""},
trim: {value:false},
base64: {/*deprecated*/ value:false, required:true},
tls: {type:"tls-config", value:'', required:false}
},
@ -286,7 +288,8 @@
<span id="node-units"></span>
</div>
<div id="node-row-newline" class="form-row hidden" style="padding-left:162px;">
<span data-i18n="tcpin.label.delimited"></span> <input type="text" id="node-input-newline" style="width:110px;" data-i18n="[placeholder]tcpin.label.optional">
<span data-i18n="tcpin.label.delimited"></span> <input type="text" id="node-input-newline" style="width:110px;" data-i18n="[placeholder]tcpin.label.optional"><br/>
<input type="checkbox" id="node-input-trim" style="display:inline-block; width:auto; vertical-align:top;"> <span data-i18n="tcpin.label.reattach"></span>
</div>
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> <span data-i18n="common.label.name"></span></label>
@ -306,6 +309,7 @@
ret: {value:"buffer"},
splitc: {value:"0", required:true},
newline: {value:""},
trim: {value:false},
tls: {type:"tls-config", value:'', required:false}
},
inputs:1,

View File

@ -88,6 +88,7 @@ module.exports = function(RED) {
this.datatype = n.datatype||'buffer'; /* buffer,utf8,base64 */
this.newline = (n.newline||"").replace("\\n","\n").replace("\\r","\r").replace("\\t","\t");
this.base64 = n.base64;
this.trim = n.trim || false;
this.server = (typeof n.server == 'boolean')?n.server:(n.server == "server");
this.closing = false;
this.connected = false;
@ -135,7 +136,8 @@ module.exports = function(RED) {
buffer = buffer+data;
var parts = buffer.split(node.newline);
for (var i = 0; i<parts.length-1; i+=1) {
msg = {topic:node.topic, payload:parts[i] + node.newline.trimEnd()};
msg = {topic:node.topic, payload:parts[i]};
if (node.trim == true) { msg.payload += node.newline.trimEnd(); }
msg._session = {type:"tcp",id:id};
node.send(msg);
}
@ -229,7 +231,8 @@ module.exports = function(RED) {
buffer = buffer+data;
var parts = buffer.split(node.newline);
for (var i = 0; i<parts.length-1; i+=1) {
msg = {topic:node.topic, payload:parts[i] + node.newline.trimEnd(), ip:socket.remoteAddress, port:socket.remotePort};
msg = {topic:node.topic, payload:parts[i], ip:socket.remoteAddress, port:socket.remotePort};
if (node.trim == true) { msg.payload += node.newline.trimEnd(); }
msg._session = {type:"tcp",id:id};
node.send(msg);
}
@ -518,6 +521,7 @@ module.exports = function(RED) {
this.out = n.out;
this.ret = n.ret || "buffer";
this.newline = (n.newline||"").replace("\\n","\n").replace("\\r","\r").replace("\\t","\t");
this.trim = n.trim || false;
this.splitc = n.splitc;
if (n.tls) {
var tlsNode = RED.nodes.getNode(n.tls);
@ -653,7 +657,8 @@ module.exports = function(RED) {
let parts = chunk.split(node.newline);
for (var p=0; p<parts.length-1; p+=1) {
let m = RED.util.cloneMessage(msg);
m.payload = parts[p] + node.newline.trimEnd();
m.payload = parts[p];
if (node.trim == true) { m.payload += node.newline.trimEnd(); }
nodeSend(m);
}
chunk = parts[parts.length-1];

View File

@ -583,7 +583,8 @@
"ms": "ms",
"chars": "chars",
"close": "Close",
"optional": "(optional)"
"optional": "(optional)",
"reattach": "re-attach delimiter and trim"
},
"type": {
"listen": "Listen on",