let daemon node pass old msg properties

This commit is contained in:
Dave Conway-Jones 2019-05-20 19:32:11 +01:00
parent f5de5bc707
commit 2070a932be
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4
2 changed files with 9 additions and 4 deletions

View File

@ -15,6 +15,7 @@ module.exports = function(RED) {
this.autorun = true;
if (n.autorun === false) { this.autorun = false; }
var node = this;
var lastmsg = {};
function inputlistener(msg) {
if (msg != null) {
@ -34,6 +35,7 @@ module.exports = function(RED) {
if (RED.settings.verbose) { node.log("inp: "+msg.payload); }
if (node.child !== null && node.running) { node.child.stdin.write(msg.payload); }
else { node.warn("Command not running"); }
lastmsg = msg;
}
}
}
@ -58,13 +60,15 @@ module.exports = function(RED) {
line += data.toString();
var bits = line.split("\n");
while (bits.length > 1) {
node.send([{payload:bits.shift()},null,null]);
lastmsg.payload = bits.shift();
node.send([lastmsg,null,null]);
}
line = bits[0];
}
else {
if (data && (data.length !== 0)) {
node.send([{payload:data},null,null]);
lastmsg.payload = data;
node.send([lastmsg,null,null]);
}
}
});
@ -73,7 +77,8 @@ module.exports = function(RED) {
if (node.op === "string") { data = data.toString(); }
if (node.op === "number") { data = Number(data); }
if (RED.settings.verbose) { node.log("err: "+data); }
node.send([null,{payload:data},null]);
lastmsg.payload = data;
node.send([null,lastmsg,null]);
});
node.child.on('close', function (code,signal) {

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-daemon",
"version" : "0.0.23",
"version" : "0.0.24",
"description" : "A Node-RED node that runs and monitors a long running system command.",
"dependencies" : {
},