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

Make sample node more representaive of a real node...

(OK not really real but at least it now doesn't fail if you try to run it)
This commit is contained in:
Dave C-J 2014-12-26 15:28:31 +00:00
parent a51056a91f
commit b4dc66944a

View File

@ -31,6 +31,7 @@ module.exports = function(RED) {
// Store local copies of the node configuration (as defined in the .html) // Store local copies of the node configuration (as defined in the .html)
this.topic = n.topic; this.topic = n.topic;
var node = this;
// Do whatever you need to do in here - declare callbacks etc // Do whatever you need to do in here - declare callbacks etc
// Note: this sample doesn't do anything much - it will only send // Note: this sample doesn't do anything much - it will only send
@ -41,19 +42,20 @@ module.exports = function(RED) {
msg.payload = "Hello world !" msg.payload = "Hello world !"
// send out the message to the rest of the workspace. // send out the message to the rest of the workspace.
this.send(msg); // ... this message will get sent at startup so you may not see it in a debug node.
node.send(msg);
// respond to inputs.... // respond to inputs....
this.on('input', function (msg) { node.on('input', function (msg) {
node.warn("I saw a payload: "+msg.payload); node.warn("I saw a payload: "+msg.payload);
// in this example just send it straight on... should process it here really // in this example just send it straight on... should process it here really
this.send(msg); node.send(msg);
}); });
this.on("close", function() { node.on("close", function() {
// Called when the node is shutdown - eg on redeploy. // Called when the node is shutdown - eg on redeploy.
// Allows ports to be closed, connections dropped etc. // Allows ports to be closed, connections dropped etc.
// eg: this.client.disconnect(); // eg: node.client.disconnect();
}); });
} }