nodes/99-sample.js.demo.js
// The main node definition - most things happen in here
The main node definition - most things happen in here
The main node definition - most things happen in here
function SampleNode(n) {
        RED.nodes.createNode(this,n);
        this.topic = n.topic;
        var msg = {};
        msg.topic = this.topic;
        msg.payload = "Hello world !"
        this.send(msg);
        this.on('input', function (msg) {
            node.warn("I saw a payload: "+msg.payload);
            this.send(msg);
        });
        this.on("close", function() {
        });
    }
function SampleNode ( n ) { RED . nodes . createNode ( this , n ) ; this . topic = n . topic ; var msg = { } ; msg . topic = this . topic ; msg . payload = "Hello world !" this . send ( msg ) ; this . on ( 'input' , function ( msg ) { node . warn ( "I saw a payload: " + msg . payload ) ; this . send ( msg ) ; } ) ; this . on ( "close" , function ( ) { } ) ; }
The main node definition - most things happen in here
The main node definition - most things happen in here
// Create a RED node // Store local copies of the node configuration (as defined in the .html) // Do whatever you need to do in here - declare callbacks etc // Note: this sample doesn't do anything much - it will only send // this message once at startup... // Look at other real nodes for some better ideas of what to do.... // send out the message to the rest of the workspace. // respond to inputs.... // in this example just send it straight on... should process it here really // Called when the node is shutdown - eg on redeploy. // Allows ports to be closed, connections dropped etc. // eg: this.client.disconnect();