blob: f9269451d9d38c7a781e2c8a640c8169cd72dfb1 [file] [log] [blame]
Timoney, Daniel (dt5972)324ee362017-02-15 10:37:53 -05001/**
2 * Copyright 2014 IBM Corp.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 **/
16
17// If you use this as a template, update the copyright with your own name.
18
19// Sample Node-RED node file
20
21
22module.exports = function(RED) {
23 "use strict";
24 // require any external libraries we may need....
25 //var foo = require("foo-library");
26
27 // The main node definition - most things happen in here
28 function SampleNode(n) {
29 // Create a RED node
30 RED.nodes.createNode(this,n);
31
32 // Store local copies of the node configuration (as defined in the .html)
33 this.topic = n.topic;
34
35 // Do whatever you need to do in here - declare callbacks etc
36 // Note: this sample doesn't do anything much - it will only send
37 // this message once at startup...
38 // Look at other real nodes for some better ideas of what to do....
39 var msg = {};
40 msg.topic = this.topic;
41 msg.payload = "Hello world !"
42
43 // send out the message to the rest of the workspace.
44 this.send(msg);
45
46 // respond to inputs....
47 this.on('input', function (msg) {
48 node.warn("I saw a payload: "+msg.payload);
49 // in this example just send it straight on... should process it here really
50 this.send(msg);
51 });
52
53 this.on("close", function() {
54 // Called when the node is shutdown - eg on redeploy.
55 // Allows ports to be closed, connections dropped etc.
56 // eg: this.client.disconnect();
57 });
58 }
59
60 // Register the node by name. This must be called before overriding any of the
61 // Node functions.
62 RED.nodes.registerType("sample",SampleNode);
63
64}