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

tweak debug - so booleans are obvious.

This commit is contained in:
Dave C-J 2013-09-13 23:28:39 +01:00
parent b0e9dbb929
commit 500c3ec146

View File

@ -28,12 +28,12 @@ function DebugNode(n) {
this.on("input",function(msg) { this.on("input",function(msg) {
if (this.active) { if (this.active) {
if (msg.payload instanceof Buffer) { if (msg.payload instanceof Buffer) {
msg.payload = "(Buffer) "+msg.payload.toString(); msg.payload = "(Buffer) "+msg.payload.toString();
} }
if (this.complete) { if (this.complete) {
DebugNode.send({id:this.id,name:this.name,topic:msg.topic,msg:msg,_path:msg._path}); DebugNode.send({id:this.id,name:this.name,topic:msg.topic,msg:msg,_path:msg._path});
} else { } else {
DebugNode.send({id:this.id,name:this.name,topic:msg.topic,msg:msg.payload,_path:msg._path}); DebugNode.send({id:this.id,name:this.name,topic:msg.topic,msg:msg.payload,_path:msg._path});
} }
} }
}); });
@ -44,7 +44,8 @@ RED.nodes.registerType("debug",DebugNode);
DebugNode.send = function(msg) { DebugNode.send = function(msg) {
if (msg.msg instanceof Error) { if (msg.msg instanceof Error) {
msg.msg = msg.msg.toString(); msg.msg = msg.msg.toString();
} else if (typeof msg.msg === 'object') { }
else if (typeof msg.msg === 'object') {
try { try {
msg.msg = "(Object) "+JSON.stringify(msg.msg,null,1); msg.msg = "(Object) "+JSON.stringify(msg.msg,null,1);
} }
@ -53,7 +54,9 @@ DebugNode.send = function(msg) {
console.log(err); console.log(err);
msg.msg = "[Error] Can't stringify object with circular reference - see console log."; msg.msg = "[Error] Can't stringify object with circular reference - see console log.";
} }
} else if (msg.msg == 0) msg.msg = "0"; }
else if (typeof msg.msg === "boolean") msg.msg = "(boolean) "+msg.msg.toString();
else if (msg.msg === 0) msg.msg = "0";
for (var i in DebugNode.activeConnections) { for (var i in DebugNode.activeConnections) {
var ws = DebugNode.activeConnections[i]; var ws = DebugNode.activeConnections[i];
@ -92,11 +95,11 @@ RED.app.post("/debug/:id", function(req,res) {
var node = RED.nodes.getNode(req.params.id); var node = RED.nodes.getNode(req.params.id);
if (node != null) { if (node != null) {
if (node.active) { if (node.active) {
node.active = false; node.active = false;
res.send(201); res.send(201);
} else { } else {
node.active = true; node.active = true;
res.send(200); res.send(200);
} }
} else { } else {
res.send(404); res.send(404);