Expand the non-functional sample to have an input to make it more useful

This commit is contained in:
Dave C-J 2014-09-18 17:06:35 +01:00
parent da61fe12d0
commit a718f34c58
2 changed files with 18 additions and 9 deletions

View File

@ -65,7 +65,7 @@
name: {value:""}, // along with default values.
topic: {value:"", required:true}
},
inputs:0, // set the number of inputs - only 0 or 1
inputs:1, // set the number of inputs - only 0 or 1
outputs:1, // set the number of outputs - 0 to n
// set the icon (held in icons dir below where you save the node)
icon: "myicon.png", // saved in icons/myicon.png

View File

@ -20,7 +20,9 @@
module.exports = function(RED) {
"use strict";
"use strict";
// require any external libraries we may need....
//var foo = require("foo-library");
// The main node definition - most things happen in here
function SampleNode(n) {
@ -41,6 +43,13 @@ module.exports = function(RED) {
// send out the message to the rest of the workspace.
this.send(msg);
// respond to inputs....
this.on('input', function (msg) {
node.warn("I saw a payload: "+msg.payload);
// in this example just send it straight on... should process it here really
this.send(msg);
}
this.on("close", function() {
// Called when the node is shutdown - eg on redeploy.
// Allows ports to be closed, connections dropped etc.