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

Migrate to new node function style

This commit is contained in:
Nick O'Leary 2014-05-03 23:32:04 +01:00
parent 5afc5857c4
commit ff49d2b217
37 changed files with 3194 additions and 3170 deletions

View File

@ -17,7 +17,7 @@
<!-- Sample html file that corresponds to the 99-sample.js file --> <!-- Sample html file that corresponds to the 99-sample.js file -->
<!-- This creates and configures the onscreen elements of the node --> <!-- This creates and configures the onscreen elements of the node -->
<!-- If you use this as a template, replace IBM Corp. with your own name. --> <!-- If you use this as a template, update the copyright with your own name. -->
<!-- First, the content of the edit dialog is defined. --> <!-- First, the content of the edit dialog is defined. -->

View File

@ -14,15 +14,15 @@
* limitations under the License. * limitations under the License.
**/ **/
// If you use this as a template, replace IBM Corp. with your own name. // If you use this as a template, update the copyright with your own name.
// Sample Node-RED node file // Sample Node-RED node file
// Require main module
var RED = require(process.env.NODE_RED_HOME+"/red/red");
// The main node definition - most things happen in here module.export = function(RED) {
function SampleNode(n) {
// The main node definition - most things happen in here
function SampleNode(n) {
// Create a RED node // Create a RED node
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
@ -45,8 +45,10 @@ function SampleNode(n) {
// Allows ports to be closed, connections dropped etc. // Allows ports to be closed, connections dropped etc.
// eg: this.client.disconnect(); // eg: this.client.disconnect();
}); });
} }
// Register the node by name. This must be called before overriding any of the // Register the node by name. This must be called before overriding any of the
// Node functions. // Node functions.
RED.nodes.registerType("sample",SampleNode); RED.nodes.registerType("sample",SampleNode);
}

View File

@ -14,10 +14,10 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var sentiment = require('sentiment'); var sentiment = require('sentiment');
function SentimentNode(n) { function SentimentNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
var node = this; var node = this;
@ -27,5 +27,6 @@ function SentimentNode(n) {
node.send(msg); node.send(msg);
}); });
}); });
}
RED.nodes.registerType("sentiment",SentimentNode);
} }
RED.nodes.registerType("sentiment",SentimentNode);

View File

@ -14,13 +14,13 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var util = require("util"); var util = require("util");
var parseString = require('xml2js').parseString; var parseString = require('xml2js').parseString;
var useColors = true; var useColors = true;
//util.inspect.styles.boolean = "red"; //util.inspect.styles.boolean = "red";
function Xml2jsNode(n) { function Xml2jsNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.useEyes = n.useEyes||false; this.useEyes = n.useEyes||false;
var node = this; var node = this;
@ -40,5 +40,6 @@ function Xml2jsNode(n) {
} }
catch(e) { util.log("[73-parsexml.js] "+e); } catch(e) { util.log("[73-parsexml.js] "+e); }
}); });
}
RED.nodes.registerType("xml2js",Xml2jsNode);
} }
RED.nodes.registerType("xml2js",Xml2jsNode);

View File

@ -14,10 +14,10 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var js2xmlparser = require("js2xmlparser"); var js2xmlparser = require("js2xmlparser");
function Js2XmlNode(n) { function Js2XmlNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.root = n.root; this.root = n.root;
var node = this; var node = this;
@ -32,5 +32,6 @@ function Js2XmlNode(n) {
} }
catch(e) { console.log(e); } catch(e) { console.log(e); }
}); });
}
RED.nodes.registerType("json2xml",Js2XmlNode);
} }
RED.nodes.registerType("json2xml",Js2XmlNode);

View File

@ -1,5 +1,5 @@
/** /**
* Copyright 2013 IBM Corp. * Copyright 2013, 2014 IBM Corp.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -14,14 +14,10 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
try {
var cron = require("cron"); var cron = require("cron");
} catch(err) {
require("util").log("[inject] Warning: cannot find module 'cron'");
}
function InjectNode(n) { function InjectNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.topic = n.topic; this.topic = n.topic;
this.payload = n.payload; this.payload = n.payload;
@ -68,11 +64,11 @@ function InjectNode(n) {
this.send(msg); this.send(msg);
msg = null; msg = null;
}); });
} }
RED.nodes.registerType("inject",InjectNode); RED.nodes.registerType("inject",InjectNode);
InjectNode.prototype.close = function() { InjectNode.prototype.close = function() {
if (this.interval_id != null) { if (this.interval_id != null) {
clearInterval(this.interval_id); clearInterval(this.interval_id);
this.log("inject: repeat stopped"); this.log("inject: repeat stopped");
@ -81,9 +77,9 @@ InjectNode.prototype.close = function() {
this.log("inject: cronjob stopped"); this.log("inject: cronjob stopped");
delete this.cronjob; delete this.cronjob;
} }
} }
RED.httpAdmin.post("/inject/:id", function(req,res) { RED.httpAdmin.post("/inject/: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) {
try { try {
@ -97,4 +93,5 @@ RED.httpAdmin.post("/inject/:id", function(req,res) {
} else { } else {
res.send(404); res.send(404);
} }
}); });
}

View File

@ -14,15 +14,15 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var util = require("util"); var util = require("util");
var ws = require("ws"); var ws = require("ws");
var events = require("events"); var events = require("events");
var debuglength = RED.settings.debugMaxLength||1000; var debuglength = RED.settings.debugMaxLength||1000;
var useColors = false; var useColors = false;
// util.inspect.styles.boolean = "red"; // util.inspect.styles.boolean = "red";
function DebugNode(n) { function DebugNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.name = n.name; this.name = n.name;
this.complete = n.complete; this.complete = n.complete;
@ -55,11 +55,11 @@ function DebugNode(n) {
} }
} }
}); });
} }
var lastSentTime = (new Date()).getTime(); var lastSentTime = (new Date()).getTime();
setInterval(function() { setInterval(function() {
var now = (new Date()).getTime(); var now = (new Date()).getTime();
if (now-lastSentTime > 15000) { if (now-lastSentTime > 15000) {
lastSentTime = now; lastSentTime = now;
@ -73,13 +73,13 @@ setInterval(function() {
} }
} }
} }
}, 15000); }, 15000);
RED.nodes.registerType("debug",DebugNode); 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') {
@ -116,15 +116,15 @@ DebugNode.send = function(msg) {
} }
} }
lastSentTime = (new Date()).getTime(); lastSentTime = (new Date()).getTime();
} }
DebugNode.activeConnections = []; DebugNode.activeConnections = [];
var path = RED.settings.httpAdminRoot || "/"; var path = RED.settings.httpAdminRoot || "/";
path = path + (path.slice(-1) == "/" ? "":"/") + "debug/ws"; path = path + (path.slice(-1) == "/" ? "":"/") + "debug/ws";
DebugNode.wsServer = new ws.Server({server:RED.server,path:path}); DebugNode.wsServer = new ws.Server({server:RED.server,path:path});
DebugNode.wsServer.on('connection',function(ws) { DebugNode.wsServer.on('connection',function(ws) {
DebugNode.activeConnections.push(ws); DebugNode.activeConnections.push(ws);
ws.on('close',function() { ws.on('close',function() {
for (var i in DebugNode.activeConnections) { for (var i in DebugNode.activeConnections) {
@ -137,21 +137,21 @@ DebugNode.wsServer.on('connection',function(ws) {
ws.on('error', function(err) { ws.on('error', function(err) {
util.log("[debug] ws error : "+err); util.log("[debug] ws error : "+err);
}); });
}); });
DebugNode.wsServer.on('error', function(err) { DebugNode.wsServer.on('error', function(err) {
util.log("[debug] ws server error : "+err); util.log("[debug] ws server error : "+err);
}); });
DebugNode.logHandler = new events.EventEmitter(); DebugNode.logHandler = new events.EventEmitter();
DebugNode.logHandler.on("log",function(msg) { DebugNode.logHandler.on("log",function(msg) {
if (msg.level == "warn" || msg.level == "error") { if (msg.level == "warn" || msg.level == "error") {
DebugNode.send(msg); DebugNode.send(msg);
} }
}); });
RED.log.addHandler(DebugNode.logHandler); RED.log.addHandler(DebugNode.logHandler);
RED.httpAdmin.post("/debug/:id/:state", function(req,res) { RED.httpAdmin.post("/debug/:id/:state", function(req,res) {
var node = RED.nodes.getNode(req.params.id); var node = RED.nodes.getNode(req.params.id);
var state = req.params.state; var state = req.params.state;
if (node != null) { if (node != null) {
@ -167,4 +167,5 @@ RED.httpAdmin.post("/debug/:id/:state", function(req,res) {
} else { } else {
res.send(404); res.send(404);
} }
}); });
}

View File

@ -14,12 +14,11 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var spawn = require('child_process').spawn;
var exec = require('child_process').exec;
var spawn = require('child_process').spawn; function ExecNode(n) {
var exec = require('child_process').exec;
function ExecNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.cmd = n.command.trim(); this.cmd = n.command.trim();
this.append = n.append.trim() || ""; this.append = n.append.trim() || "";
@ -76,6 +75,7 @@ function ExecNode(n) {
} }
}); });
} }
RED.nodes.registerType("exec",ExecNode); RED.nodes.registerType("exec",ExecNode);
}

View File

@ -14,14 +14,13 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var util = require("util");
var vm = require("vm");
var fs = require('fs');
var fspath = require('path');
var util = require("util"); function FunctionNode(n) {
var vm = require("vm");
var fs = require('fs');
var fspath = require('path');
function FunctionNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.name = n.name; this.name = n.name;
this.func = n.func; this.func = n.func;
@ -65,7 +64,8 @@ function FunctionNode(n) {
} catch(err) { } catch(err) {
this.error(err); this.error(err);
} }
} }
RED.nodes.registerType("function",FunctionNode); RED.nodes.registerType("function",FunctionNode);
RED.library.register("functions"); RED.library.register("functions");
}

View File

@ -14,13 +14,12 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var mustache = require("mustache");
var util = require("util");
var fs = require('fs');
var mustache = require("mustache"); function TemplateNode(n) {
var util = require("util");
var fs = require('fs');
function TemplateNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.name = n.name; this.name = n.name;
this.template = n.template; this.template = n.template;
@ -34,8 +33,9 @@ function TemplateNode(n) {
} }
} }
}); });
}
RED.nodes.registerType("template",TemplateNode);
RED.library.register("templates");
} }
RED.nodes.registerType("template",TemplateNode);
RED.library.register("templates");

View File

@ -15,9 +15,8 @@
**/ **/
//Simple node to introduce a pause into a flow //Simple node to introduce a pause into a flow
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
function random(n) {
function random(n) {
var wait = n.randomFirst + (n.diff * Math.random()); var wait = n.randomFirst + (n.diff * Math.random());
if (n.buffer.length > 0) { if (n.buffer.length > 0) {
n.send(n.buffer.pop()); n.send(n.buffer.pop());
@ -25,9 +24,9 @@ function random(n) {
} else { } else {
n.randomID = -1; n.randomID = -1;
} }
} }
function DelayNode(n) { function DelayNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.pauseType = n.pauseType; this.pauseType = n.pauseType;
@ -150,5 +149,6 @@ function DelayNode(n) {
} }
}); });
} }
}
RED.nodes.registerType("delay",DelayNode);
} }
RED.nodes.registerType("delay",DelayNode);

View File

@ -14,10 +14,10 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
function CommentNode(n) {
function CommentNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
} }
RED.nodes.registerType("comment",CommentNode); RED.nodes.registerType("comment",CommentNode);
}

View File

@ -14,9 +14,9 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
function UnknownNode(n) {
function UnknownNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
}
RED.nodes.registerType("unknown",UnknownNode);
} }
RED.nodes.registerType("unknown",UnknownNode);

View File

@ -14,14 +14,15 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var util = require("util");
var firmata = require("firmata");
var arduinoReady = false;
var thisboard = null;
// The Board Definition - this opens (and closes) the connection var util = require("util");
function ArduinoNode(n) { var firmata = require("firmata");
var arduinoReady = false;
var thisboard = null;
// The Board Definition - this opens (and closes) the connection
function ArduinoNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.device = n.device; this.device = n.device;
this.repeat = n.repeat||25; this.repeat = n.repeat||25;
@ -62,12 +63,12 @@ function ArduinoNode(n) {
} }
util.log("[firmata] Stopped"); util.log("[firmata] Stopped");
}); });
} }
RED.nodes.registerType("arduino-board",ArduinoNode); RED.nodes.registerType("arduino-board",ArduinoNode);
// The Input Node // The Input Node
function DuinoNodeIn(n) { function DuinoNodeIn(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.buttonState = -1; this.buttonState = -1;
this.pin = n.pin; this.pin = n.pin;
@ -117,12 +118,12 @@ function DuinoNodeIn(n) {
else { else {
util.log("[firmata] Serial Port not Configured"); util.log("[firmata] Serial Port not Configured");
} }
} }
RED.nodes.registerType("arduino in",DuinoNodeIn); RED.nodes.registerType("arduino in",DuinoNodeIn);
// The Output Node // The Output Node
function DuinoNodeOut(n) { function DuinoNodeOut(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.buttonState = -1; this.buttonState = -1;
this.pin = n.pin; this.pin = n.pin;
@ -183,5 +184,6 @@ function DuinoNodeOut(n) {
else { else {
util.log("[firmata] Serial Port not Configured"); util.log("[firmata] Serial Port not Configured");
} }
}
RED.nodes.registerType("arduino out",DuinoNodeOut);
} }
RED.nodes.registerType("arduino out",DuinoNodeOut);

View File

@ -14,22 +14,22 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var util = require("util"); var util = require("util");
var exec = require('child_process').exec; var exec = require('child_process').exec;
var fs = require('fs'); var fs = require('fs');
if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi if (!fs.existsSync("/dev/ttyAMA0")) { // unlikely if not on a Pi
throw "Info : Ignoring Raspberry Pi specific node."; throw "Info : Ignoring Raspberry Pi specific node.";
} }
if (!fs.existsSync("/usr/local/bin/gpio")) { // gpio command not installed if (!fs.existsSync("/usr/local/bin/gpio")) { // gpio command not installed
throw "Info : Can't find Raspberry Pi wiringPi gpio command."; throw "Info : Can't find Raspberry Pi wiringPi gpio command.";
} }
// Map physical P1 pins to Gordon's Wiring-Pi Pins (as they should be V1/V2 tolerant) // Map physical P1 pins to Gordon's Wiring-Pi Pins (as they should be V1/V2 tolerant)
var pintable = { var pintable = {
// Physical : WiringPi // Physical : WiringPi
"11":"0", "11":"0",
"12":"1", "12":"1",
"13":"2", "13":"2",
@ -47,9 +47,9 @@ var pintable = {
"23":"14", "23":"14",
"8":"15", "8":"15",
"10":"16" "10":"16"
} }
var tablepin = { var tablepin = {
// WiringPi : Physical // WiringPi : Physical
"0":"11", "0":"11",
"1":"12", "1":"12",
"2":"13", "2":"13",
@ -67,9 +67,9 @@ var tablepin = {
"14":"23", "14":"23",
"15":"8", "15":"8",
"16":"10" "16":"10"
} }
function GPIOInNode(n) { function GPIOInNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.buttonState = -1; this.buttonState = -1;
this.pin = pintable[n.pin]; this.pin = pintable[n.pin];
@ -105,9 +105,9 @@ function GPIOInNode(n) {
this.on("close", function() { this.on("close", function() {
clearInterval(this._interval); clearInterval(this._interval);
}); });
} }
function GPIOOutNode(n) { function GPIOOutNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.pin = pintable[n.pin]; this.pin = pintable[n.pin];
var node = this; var node = this;
@ -139,9 +139,9 @@ function GPIOOutNode(n) {
this.on("close", function() { this.on("close", function() {
exec("gpio mode "+this.pin+" in"); exec("gpio mode "+this.pin+" in");
}); });
} }
exec("gpio mode 0 in",function(err,stdout,stderr) { exec("gpio mode 0 in",function(err,stdout,stderr) {
if (err) { if (err) {
util.log('[36-rpi-gpio.js] Error: "gpio" command failed for some reason.'); util.log('[36-rpi-gpio.js] Error: "gpio" command failed for some reason.');
} }
@ -152,7 +152,8 @@ exec("gpio mode 0 in",function(err,stdout,stderr) {
exec("gpio mode 5 in"); exec("gpio mode 5 in");
exec("gpio mode 6 in"); exec("gpio mode 6 in");
exec("gpio mode 7 in"); exec("gpio mode 7 in");
}); });
RED.nodes.registerType("rpi-gpio in",GPIOInNode); RED.nodes.registerType("rpi-gpio in",GPIOInNode);
RED.nodes.registerType("rpi-gpio out",GPIOOutNode); RED.nodes.registerType("rpi-gpio out",GPIOOutNode);
}

View File

@ -14,11 +14,12 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var connectionPool = require("./lib/mqttConnectionPool");
var util = require("util");
function MQTTBrokerNode(n) { var connectionPool = require("./lib/mqttConnectionPool");
var util = require("util");
function MQTTBrokerNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.broker = n.broker; this.broker = n.broker;
this.port = n.port; this.port = n.port;
@ -28,26 +29,26 @@ function MQTTBrokerNode(n) {
this.username = credentials.user; this.username = credentials.user;
this.password = credentials.password; this.password = credentials.password;
} }
} }
RED.nodes.registerType("mqtt-broker",MQTTBrokerNode); RED.nodes.registerType("mqtt-broker",MQTTBrokerNode);
var querystring = require('querystring'); var querystring = require('querystring');
RED.httpAdmin.get('/mqtt-broker/:id',function(req,res) { RED.httpAdmin.get('/mqtt-broker/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id); var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) { if (credentials) {
res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!="")})); res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!="")}));
} else { } else {
res.send(JSON.stringify({})); res.send(JSON.stringify({}));
} }
}); });
RED.httpAdmin.delete('/mqtt-broker/:id',function(req,res) { RED.httpAdmin.delete('/mqtt-broker/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id); RED.nodes.deleteCredentials(req.params.id);
res.send(200); res.send(200);
}); });
RED.httpAdmin.post('/mqtt-broker/:id',function(req,res) { RED.httpAdmin.post('/mqtt-broker/:id',function(req,res) {
var body = ""; var body = "";
req.on('data', function(chunk) { req.on('data', function(chunk) {
body+=chunk; body+=chunk;
@ -68,10 +69,10 @@ RED.httpAdmin.post('/mqtt-broker/:id',function(req,res) {
RED.nodes.addCredentials(req.params.id,credentials); RED.nodes.addCredentials(req.params.id,credentials);
res.send(200); res.send(200);
}); });
}); });
function MQTTInNode(n) { function MQTTInNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.topic = n.topic; this.topic = n.topic;
this.broker = n.broker; this.broker = n.broker;
@ -90,18 +91,18 @@ function MQTTInNode(n) {
} else { } else {
this.error("missing broker configuration"); this.error("missing broker configuration");
} }
} }
RED.nodes.registerType("mqtt in",MQTTInNode); RED.nodes.registerType("mqtt in",MQTTInNode);
MQTTInNode.prototype.close = function() { MQTTInNode.prototype.close = function() {
if (this.client) { if (this.client) {
this.client.disconnect(); this.client.disconnect();
} }
} }
function MQTTOutNode(n) { function MQTTOutNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.topic = n.topic; this.topic = n.topic;
@ -123,13 +124,14 @@ function MQTTOutNode(n) {
} else { } else {
this.error("missing broker configuration"); this.error("missing broker configuration");
} }
} }
RED.nodes.registerType("mqtt out",MQTTOutNode); RED.nodes.registerType("mqtt out",MQTTOutNode);
MQTTOutNode.prototype.close = function() { MQTTOutNode.prototype.close = function() {
if (this.client) { if (this.client) {
this.client.disconnect(); this.client.disconnect();
} }
}
} }

View File

@ -14,21 +14,22 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var util = require("util");
var http = require("follow-redirects").http;
var https = require("follow-redirects").https;
var urllib = require("url");
var express = require("express");
var getBody = require('raw-body');
var mustache = require("mustache");
var querystring = require("querystring");
var cors = require('cors'); var util = require("util");
var jsonParser = express.json(); var http = require("follow-redirects").http;
var urlencParser = express.urlencoded(); var https = require("follow-redirects").https;
var urllib = require("url");
var express = require("express");
var getBody = require('raw-body');
var mustache = require("mustache");
var querystring = require("querystring");
function rawBodyParser(req, res, next) { var cors = require('cors');
var jsonParser = express.json();
var urlencParser = express.urlencoded();
function rawBodyParser(req, res, next) {
if (req._body) return next(); if (req._body) return next();
req.body = ""; req.body = "";
req._body = true; req._body = true;
@ -41,10 +42,10 @@ function rawBodyParser(req, res, next) {
req.body = buf; req.body = buf;
next(); next();
}); });
} }
function HTTPIn(n) { function HTTPIn(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
if (RED.settings.httpNodeRoot !== false) { if (RED.settings.httpNodeRoot !== false) {
@ -106,11 +107,11 @@ function HTTPIn(n) {
} else { } else {
this.warn("Cannot create http-in node when httpNodeRoot set to false"); this.warn("Cannot create http-in node when httpNodeRoot set to false");
} }
} }
RED.nodes.registerType("http in",HTTPIn); RED.nodes.registerType("http in",HTTPIn);
function HTTPOut(n) { function HTTPOut(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
var node = this; var node = this;
this.on("input",function(msg) { this.on("input",function(msg) {
@ -128,10 +129,10 @@ function HTTPOut(n) {
node.warn("No response object"); node.warn("No response object");
} }
}); });
} }
RED.nodes.registerType("http response",HTTPOut); RED.nodes.registerType("http response",HTTPOut);
function HTTPRequest(n) { function HTTPRequest(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
var nodeUrl = n.url; var nodeUrl = n.url;
var isTemplatedUrl = (nodeUrl||"").indexOf("{{") != -1; var isTemplatedUrl = (nodeUrl||"").indexOf("{{") != -1;
@ -204,24 +205,24 @@ function HTTPRequest(n) {
} }
req.end(); req.end();
}); });
} }
RED.nodes.registerType("http request",HTTPRequest); RED.nodes.registerType("http request",HTTPRequest);
RED.httpAdmin.get('/http-request/:id',function(req,res) { RED.httpAdmin.get('/http-request/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id); var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) { if (credentials) {
res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!="")})); res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!="")}));
} else { } else {
res.send(JSON.stringify({})); res.send(JSON.stringify({}));
} }
}); });
RED.httpAdmin.delete('/http-request/:id',function(req,res) { RED.httpAdmin.delete('/http-request/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id); RED.nodes.deleteCredentials(req.params.id);
res.send(200); res.send(200);
}); });
RED.httpAdmin.post('/http-request/:id',function(req,res) { RED.httpAdmin.post('/http-request/:id',function(req,res) {
var body = ""; var body = "";
req.on('data', function(chunk) { req.on('data', function(chunk) {
body+=chunk; body+=chunk;
@ -242,4 +243,5 @@ RED.httpAdmin.post('/http-request/:id',function(req,res) {
RED.nodes.addCredentials(req.params.id,credentials); RED.nodes.addCredentials(req.params.id,credentials);
res.send(200); res.send(200);
}); });
}); });
}

View File

@ -14,13 +14,13 @@
* limitations under the License. * limitations under the License.
**/ **/
// Require main module module.exports = function(RED) {
var RED = require(process.env.NODE_RED_HOME+"/red/red"),
ws = require("ws"), var ws = require("ws"),
inspect = require("sys").inspect; inspect = require("sys").inspect;
// A node red node that sets up a local websocket server // A node red node that sets up a local websocket server
function WebSocketListenerNode(n) { function WebSocketListenerNode(n) {
// Create a RED node // Create a RED node
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
@ -86,14 +86,14 @@ function WebSocketListenerNode(n) {
node.server.close(); node.server.close();
node._inputNodes = []; node._inputNodes = [];
}); });
} }
RED.nodes.registerType("websocket-listener",WebSocketListenerNode); RED.nodes.registerType("websocket-listener",WebSocketListenerNode);
WebSocketListenerNode.prototype.registerInputNode = function(/*Node*/handler){ WebSocketListenerNode.prototype.registerInputNode = function(/*Node*/handler){
this._inputNodes.push(handler); this._inputNodes.push(handler);
} }
WebSocketListenerNode.prototype.handleEvent = function(id,/*socket*/socket,/*String*/event,/*Object*/data,/*Object*/flags){ WebSocketListenerNode.prototype.handleEvent = function(id,/*socket*/socket,/*String*/event,/*Object*/data,/*Object*/flags){
var msg; var msg;
if (this.wholemsg) { if (this.wholemsg) {
msg = JSON.parse(data); msg = JSON.parse(data);
@ -107,22 +107,22 @@ WebSocketListenerNode.prototype.handleEvent = function(id,/*socket*/socket,/*Str
for (var i = 0; i < this._inputNodes.length; i++) { for (var i = 0; i < this._inputNodes.length; i++) {
this._inputNodes[i].send(msg); this._inputNodes[i].send(msg);
}; };
} }
WebSocketListenerNode.prototype.broadcast = function(data){ WebSocketListenerNode.prototype.broadcast = function(data){
for(var i in this.server.clients){ for(var i in this.server.clients){
this.server.clients[i].send(data); this.server.clients[i].send(data);
}; };
} }
WebSocketListenerNode.prototype.send = function(id,data){ WebSocketListenerNode.prototype.send = function(id,data){
var session = this._clients[id]; var session = this._clients[id];
if (session) { if (session) {
session.send(data); session.send(data);
} }
} }
function WebSocketInNode(n) { function WebSocketInNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.server = n.server; this.server = n.server;
var node = this; var node = this;
@ -132,10 +132,10 @@ function WebSocketInNode(n) {
} else { } else {
this.error("Missing server configuration"); this.error("Missing server configuration");
} }
} }
RED.nodes.registerType("websocket in",WebSocketInNode); RED.nodes.registerType("websocket in",WebSocketInNode);
function WebSocketOutNode(n) { function WebSocketOutNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
var node = this; var node = this;
this.server = n.server; this.server = n.server;
@ -168,5 +168,6 @@ function WebSocketOutNode(n) {
}); });
} }
}); });
}
RED.nodes.registerType("websocket out",WebSocketOutNode);
} }
RED.nodes.registerType("websocket out",WebSocketOutNode);

View File

@ -14,12 +14,12 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var notify = require("fs.notify"); var notify = require("fs.notify");
var fs = require("fs"); var fs = require("fs");
var sep = require("path").sep; var sep = require("path").sep;
function WatchNode(n) { function WatchNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.files = n.files.split(","); this.files = n.files.split(",");
@ -38,5 +38,6 @@ function WatchNode(n) {
this.close = function() { this.close = function() {
notifications.close(); notifications.close();
} }
}
RED.nodes.registerType("watch",WatchNode);
} }
RED.nodes.registerType("watch",WatchNode);

View File

@ -14,15 +14,15 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var settings = RED.settings; var settings = RED.settings;
var events = require("events"); var events = require("events");
var util = require("util"); var util = require("util");
var serialp = require("serialport"); var serialp = require("serialport");
// TODO: 'serialPool' should be encapsulated in SerialPortNode // TODO: 'serialPool' should be encapsulated in SerialPortNode
function SerialPortNode(n) { function SerialPortNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.serialport = n.serialport; this.serialport = n.serialport;
this.newline = n.newline; this.newline = n.newline;
@ -32,10 +32,10 @@ function SerialPortNode(n) {
this.databits = parseInt(n.databits) || 8; this.databits = parseInt(n.databits) || 8;
this.parity = n.parity || "none"; this.parity = n.parity || "none";
this.stopbits = parseInt(n.stopbits) || 1; this.stopbits = parseInt(n.stopbits) || 1;
} }
RED.nodes.registerType("serial-port",SerialPortNode); RED.nodes.registerType("serial-port",SerialPortNode);
function SerialOutNode(n) { function SerialOutNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.serial = n.serial; this.serial = n.serial;
this.serialConfig = RED.nodes.getNode(this.serial); this.serialConfig = RED.nodes.getNode(this.serial);
@ -79,10 +79,10 @@ function SerialOutNode(n) {
serialPool.close(this.serialConfig.serialport); serialPool.close(this.serialConfig.serialport);
} }
}); });
} }
RED.nodes.registerType("serial out",SerialOutNode); RED.nodes.registerType("serial out",SerialOutNode);
function SerialInNode(n) { function SerialInNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.serial = n.serial; this.serial = n.serial;
this.serialConfig = RED.nodes.getNode(this.serial); this.serialConfig = RED.nodes.getNode(this.serial);
@ -110,11 +110,11 @@ function SerialInNode(n) {
} }
} }
}); });
} }
RED.nodes.registerType("serial in",SerialInNode); RED.nodes.registerType("serial in",SerialInNode);
var serialPool = function() { var serialPool = function() {
var connections = {}; var connections = {};
return { return {
get:function(port,baud,databits,parity,stopbits,newline,callback) { get:function(port,baud,databits,parity,stopbits,newline,callback) {
@ -201,12 +201,13 @@ var serialPool = function() {
delete connections[port]; delete connections[port];
} }
} }
}(); }();
RED.httpAdmin.get("/serialports",function(req,res) { RED.httpAdmin.get("/serialports",function(req,res) {
serialp.list(function (err, ports) { serialp.list(function (err, ports) {
res.writeHead(200, {'Content-Type': 'text/plain'}); res.writeHead(200, {'Content-Type': 'text/plain'});
res.write(JSON.stringify(ports)); res.write(JSON.stringify(ports));
res.end(); res.end();
}); });
}); });
}

View File

@ -14,14 +14,14 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var reconnectTime = RED.settings.socketReconnectTime||10000; var reconnectTime = RED.settings.socketReconnectTime||10000;
var socketTimeout = RED.settings.socketTimeout||null; var socketTimeout = RED.settings.socketTimeout||null;
var net = require('net'); var net = require('net');
var connectionPool = {}; var connectionPool = {};
function TcpIn(n) { function TcpIn(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.host = n.host; this.host = n.host;
this.port = n.port * 1; this.port = n.port * 1;
@ -174,10 +174,10 @@ function TcpIn(n) {
}); });
} }
} }
RED.nodes.registerType("tcp in",TcpIn); RED.nodes.registerType("tcp in",TcpIn);
function TcpOut(n) { function TcpOut(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.host = n.host; this.host = n.host;
this.port = n.port * 1; this.port = n.port * 1;
@ -301,6 +301,7 @@ function TcpOut(n) {
} }
}); });
} }
} }
RED.nodes.registerType("tcp out",TcpOut); RED.nodes.registerType("tcp out",TcpOut);
}

View File

@ -14,11 +14,11 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var dgram = require('dgram'); var dgram = require('dgram');
// The Input Node // The Input Node
function UDPin(n) { function UDPin(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.group = n.group; this.group = n.group;
this.port = n.port; this.port = n.port;
@ -81,12 +81,12 @@ function UDPin(n) {
}); });
server.bind(node.port,node.iface); server.bind(node.port,node.iface);
} }
RED.nodes.registerType("udp in",UDPin); RED.nodes.registerType("udp in",UDPin);
// The Output Node // The Output Node
function UDPout(n) { function UDPout(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
//this.group = n.group; //this.group = n.group;
this.port = n.port; this.port = n.port;
@ -164,5 +164,6 @@ function UDPout(n) {
node.error(err); node.error(err);
} }
}); });
}
RED.nodes.registerType("udp out",UDPout);
} }
RED.nodes.registerType("udp out",UDPout);

View File

@ -14,9 +14,8 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME + "/red/red"); module.exports = function(RED) {
var operators = {
var operators = {
'eq': function(a, b) { return a == b; }, 'eq': function(a, b) { return a == b; },
'neq': function(a, b) { return a != b; }, 'neq': function(a, b) { return a != b; },
'lt': function(a, b) { return a < b; }, 'lt': function(a, b) { return a < b; },
@ -31,9 +30,9 @@ var operators = {
'null': function(a) { return typeof a == "undefined"; }, 'null': function(a) { return typeof a == "undefined"; },
'nnull': function(a) { return typeof a != "undefined"; }, 'nnull': function(a) { return typeof a != "undefined"; },
'else': function(a) { return a === true; } 'else': function(a) { return a === true; }
}; };
function SwitchNode(n) { function SwitchNode(n) {
RED.nodes.createNode(this, n); RED.nodes.createNode(this, n);
this.rules = n.rules; this.rules = n.rules;
this.property = n.property; this.property = n.property;
@ -69,5 +68,6 @@ function SwitchNode(n) {
} }
this.send(onward); this.send(onward);
}); });
}
RED.nodes.registerType("switch", SwitchNode);
} }
RED.nodes.registerType("switch", SwitchNode);

View File

@ -14,9 +14,8 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME + "/red/red"); module.exports = function(RED) {
function ChangeNode(n) {
function ChangeNode(n) {
RED.nodes.createNode(this, n); RED.nodes.createNode(this, n);
this.action = n.action; this.action = n.action;
this.property = n.property || ""; this.property = n.property || "";
@ -69,5 +68,6 @@ function ChangeNode(n) {
} }
node.send(msg); node.send(msg);
}); });
}
RED.nodes.registerType("change", ChangeNode);
} }
RED.nodes.registerType("change", ChangeNode);

View File

@ -14,9 +14,8 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME + "/red/red"); module.exports = function(RED) {
function RangeNode(n) {
function RangeNode(n) {
RED.nodes.createNode(this, n); RED.nodes.createNode(this, n);
this.action = n.action; this.action = n.action;
this.round = n.round || false; this.round = n.round || false;
@ -43,5 +42,6 @@ function RangeNode(n) {
} }
else { node.log("Not a number: "+msg.payload); } else { node.log("Not a number: "+msg.payload); }
}); });
}
RED.nodes.registerType("range", RangeNode);
} }
RED.nodes.registerType("range", RangeNode);

View File

@ -14,9 +14,8 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
function CSVNode(n) {
function CSVNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.template = n.temp.split(","); this.template = n.temp.split(",");
this.sep = n.sep || ','; this.sep = n.sep || ',';
@ -74,5 +73,6 @@ function CSVNode(n) {
else { node.log("This node only handles csv strings or js objects."); } else { node.log("This node only handles csv strings or js objects."); }
} }
}); });
}
RED.nodes.registerType("csv",CSVNode);
} }
RED.nodes.registerType("csv",CSVNode);

View File

@ -14,10 +14,10 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var util = require("util"); var util = require("util");
function JSONNode(n) { function JSONNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
var node = this; var node = this;
this.on("input", function(msg) { this.on("input", function(msg) {
@ -40,5 +40,6 @@ function JSONNode(n) {
else { node.log("dropped: "+msg.payload); } else { node.log("dropped: "+msg.payload); }
} }
}); });
}
RED.nodes.registerType("json",JSONNode);
} }
RED.nodes.registerType("json",JSONNode);

View File

@ -14,12 +14,12 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var xml2js = require('xml2js'); var xml2js = require('xml2js');
var parseString = xml2js.parseString; var parseString = xml2js.parseString;
var builder = new xml2js.Builder({renderOpts:{pretty:false}}); var builder = new xml2js.Builder({renderOpts:{pretty:false}});
function XMLNode(n) { function XMLNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
var node = this; var node = this;
this.on("input", function(msg) { this.on("input", function(msg) {
@ -46,5 +46,6 @@ function XMLNode(n) {
else { node.log("This node only handles xml strings or js objects."); } else { node.log("This node only handles xml strings or js objects."); }
} }
}); });
}
RED.nodes.registerType("xml",XMLNode);
} }
RED.nodes.registerType("xml",XMLNode);

View File

@ -14,17 +14,17 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var ntwitter = require('twitter-ng'); var ntwitter = require('twitter-ng');
var OAuth= require('oauth').OAuth; var OAuth= require('oauth').OAuth;
function TwitterNode(n) { function TwitterNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.screen_name = n.screen_name; this.screen_name = n.screen_name;
} }
RED.nodes.registerType("twitter-credentials",TwitterNode); RED.nodes.registerType("twitter-credentials",TwitterNode);
function TwitterInNode(n) { function TwitterInNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.active = true; this.active = true;
this.user = n.user; this.user = n.user;
@ -212,11 +212,11 @@ function TwitterInNode(n) {
} }
} }
}); });
} }
RED.nodes.registerType("twitter in",TwitterInNode); RED.nodes.registerType("twitter in",TwitterInNode);
function TwitterOutNode(n) { function TwitterOutNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.topic = n.topic; this.topic = n.topic;
this.twitter = n.twitter; this.twitter = n.twitter;
@ -248,10 +248,10 @@ function TwitterOutNode(n) {
} }
}); });
} }
} }
RED.nodes.registerType("twitter out",TwitterOutNode); RED.nodes.registerType("twitter out",TwitterOutNode);
var oa = new OAuth( var oa = new OAuth(
"https://api.twitter.com/oauth/request_token", "https://api.twitter.com/oauth/request_token",
"https://api.twitter.com/oauth/access_token", "https://api.twitter.com/oauth/access_token",
"OKjYEd1ef2bfFolV25G5nQ", "OKjYEd1ef2bfFolV25G5nQ",
@ -259,25 +259,25 @@ var oa = new OAuth(
"1.0", "1.0",
null, null,
"HMAC-SHA1" "HMAC-SHA1"
); );
var credentials = {}; var credentials = {};
RED.httpAdmin.get('/twitter/:id', function(req,res) { RED.httpAdmin.get('/twitter/:id', function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id); var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) { if (credentials) {
res.send(JSON.stringify({sn:credentials.screen_name})); res.send(JSON.stringify({sn:credentials.screen_name}));
} else { } else {
res.send(JSON.stringify({})); res.send(JSON.stringify({}));
} }
}); });
RED.httpAdmin.delete('/twitter/:id', function(req,res) { RED.httpAdmin.delete('/twitter/:id', function(req,res) {
RED.nodes.deleteCredentials(req.params.id); RED.nodes.deleteCredentials(req.params.id);
res.send(200); res.send(200);
}); });
RED.httpAdmin.get('/twitter/:id/auth', function(req, res){ RED.httpAdmin.get('/twitter/:id/auth', function(req, res){
var credentials = {}; var credentials = {};
oa.getOAuthRequestToken({ oa.getOAuthRequestToken({
oauth_callback: req.query.callback oauth_callback: req.query.callback
@ -295,9 +295,9 @@ RED.httpAdmin.get('/twitter/:id/auth', function(req, res){
RED.nodes.addCredentials(req.params.id,credentials); RED.nodes.addCredentials(req.params.id,credentials);
} }
}); });
}); });
RED.httpAdmin.get('/twitter/:id/auth/callback', function(req, res, next){ RED.httpAdmin.get('/twitter/:id/auth/callback', function(req, res, next){
var credentials = RED.nodes.getCredentials(req.params.id); var credentials = RED.nodes.getCredentials(req.params.id);
credentials.oauth_verifier = req.query.oauth_verifier; credentials.oauth_verifier = req.query.oauth_verifier;
@ -319,4 +319,5 @@ RED.httpAdmin.get('/twitter/:id/auth/callback', function(req, res, next){
} }
} }
); );
}); });
}

View File

@ -14,11 +14,11 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var FeedParser = require("feedparser"); var FeedParser = require("feedparser");
var request = require("request"); var request = require("request");
function FeedParseNode(n) { function FeedParseNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.url = n.url; this.url = n.url;
this.interval = (parseInt(n.interval)||15)*60000; this.interval = (parseInt(n.interval)||15)*60000;
@ -58,14 +58,14 @@ function FeedParseNode(n) {
} else { } else {
this.error("Invalid url"); this.error("Invalid url");
} }
} }
RED.nodes.registerType("feedparse",FeedParseNode); RED.nodes.registerType("feedparse",FeedParseNode);
FeedParseNode.prototype.close = function() { FeedParseNode.prototype.close = function() {
if (this.interval_id != null) { if (this.interval_id != null) {
clearInterval(this.interval_id); clearInterval(this.interval_id);
} }
}
} }

View File

@ -14,23 +14,23 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var util = require('util'); var util = require('util');
var nodemailer = require("nodemailer"); var nodemailer = require("nodemailer");
var Imap = null; var Imap = null;
try { try {
Imap = require('imap'); Imap = require('imap');
} catch (e) { } catch (e) {
util.log("[61-email.js] - imap npm not installed - no inbound email available"); util.log("[61-email.js] - imap npm not installed - no inbound email available");
} }
//console.log(nodemailer.Transport.transports.SMTP.wellKnownHosts); //console.log(nodemailer.Transport.transports.SMTP.wellKnownHosts);
// module.exports = { service: "Gmail", user: "blahblah@gmail.com", pass: "password", server: "imap.gmail.com", port: "993" } // module.exports = { service: "Gmail", user: "blahblah@gmail.com", pass: "password", server: "imap.gmail.com", port: "993" }
try { var globalkeys = RED.settings.email || require(process.env.NODE_RED_HOME+"/../emailkeys.js"); } try { var globalkeys = RED.settings.email || require(process.env.NODE_RED_HOME+"/../emailkeys.js"); }
catch(err) { } catch(err) { }
function EmailNode(n) { function EmailNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.topic = n.topic; this.topic = n.topic;
this.name = n.name; this.name = n.name;
@ -87,10 +87,10 @@ function EmailNode(n) {
else { node.warn("No Email credentials found. See info panel."); } else { node.warn("No Email credentials found. See info panel."); }
} }
}); });
} }
RED.nodes.registerType("e-mail",EmailNode); RED.nodes.registerType("e-mail",EmailNode);
function EmailInNode(n) { function EmailInNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.name = n.name; this.name = n.name;
this.repeat = n.repeat * 1000 || 300000; this.repeat = n.repeat * 1000 || 300000;
@ -205,18 +205,18 @@ function EmailInNode(n) {
}); });
node.emit("input",{}); node.emit("input",{});
} }
if (Imap != null) { if (Imap != null) {
RED.nodes.registerType("e-mail in",EmailInNode); RED.nodes.registerType("e-mail in",EmailInNode);
} }
var querystring = require('querystring'); var querystring = require('querystring');
RED.httpAdmin.get('/email/global',function(req,res) { RED.httpAdmin.get('/email/global',function(req,res) {
res.send(JSON.stringify({hasToken:!(globalkeys && globalkeys.userid && globalkeys.password)})); res.send(JSON.stringify({hasToken:!(globalkeys && globalkeys.userid && globalkeys.password)}));
}); });
RED.httpAdmin.get('/email/:id',function(req,res) { RED.httpAdmin.get('/email/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id); var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) { if (credentials) {
res.send(JSON.stringify({userid:credentials.userid,hasPassword:(credentials.password&&credentials.password!="")})); res.send(JSON.stringify({userid:credentials.userid,hasPassword:(credentials.password&&credentials.password!="")}));
@ -229,14 +229,14 @@ RED.httpAdmin.get('/email/:id',function(req,res) {
else { else {
res.send(JSON.stringify({})); res.send(JSON.stringify({}));
} }
}); });
RED.httpAdmin.delete('/email/:id',function(req,res) { RED.httpAdmin.delete('/email/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id); RED.nodes.deleteCredentials(req.params.id);
res.send(200); res.send(200);
}); });
RED.httpAdmin.post('/email/:id',function(req,res) { RED.httpAdmin.post('/email/:id',function(req,res) {
var body = ""; var body = "";
req.on('data', function(chunk) { req.on('data', function(chunk) {
body+=chunk; body+=chunk;
@ -257,4 +257,5 @@ RED.httpAdmin.post('/email/:id',function(req,res) {
RED.nodes.addCredentials(req.params.id,credentials); RED.nodes.addCredentials(req.params.id,credentials);
res.send(200); res.send(200);
}); });
}); });
}

View File

@ -14,12 +14,12 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var irc = require("irc"); var irc = require("irc");
var util = require("util"); var util = require("util");
// The Server Definition - this opens (and closes) the connection // The Server Definition - this opens (and closes) the connection
function IRCServerNode(n) { function IRCServerNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.server = n.server; this.server = n.server;
this.channel = n.channel; this.channel = n.channel;
@ -30,12 +30,12 @@ function IRCServerNode(n) {
this.ircclient.disconnect(); this.ircclient.disconnect();
} }
}); });
} }
RED.nodes.registerType("irc-server",IRCServerNode); RED.nodes.registerType("irc-server",IRCServerNode);
// The Input Node // The Input Node
function IrcInNode(n) { function IrcInNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.ircserver = n.ircserver; this.ircserver = n.ircserver;
this.serverConfig = RED.nodes.getNode(this.ircserver); this.serverConfig = RED.nodes.getNode(this.ircserver);
@ -87,12 +87,12 @@ function IrcInNode(n) {
node.log(who+' was kicked from '+channel+' by '+by+': '+reason); node.log(who+' was kicked from '+channel+' by '+by+': '+reason);
}); });
} }
RED.nodes.registerType("irc in",IrcInNode); RED.nodes.registerType("irc in",IrcInNode);
// The Output Node // The Output Node
function IrcOutNode(n) { function IrcOutNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.sendAll = n.sendObject; this.sendAll = n.sendObject;
this.ircserver = n.ircserver; this.ircserver = n.ircserver;
@ -136,5 +136,6 @@ function IrcOutNode(n) {
} }
} }
}); });
}
RED.nodes.registerType("irc out",IrcOutNode);
} }
RED.nodes.registerType("irc out",IrcOutNode);

View File

@ -14,11 +14,11 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var fs = require("fs"); var fs = require("fs");
var spawn = require('child_process').spawn; var spawn = require('child_process').spawn;
function TailNode(n) { function TailNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.filename = n.filename; this.filename = n.filename;
@ -51,6 +51,7 @@ function TailNode(n) {
this.on("close", function() { this.on("close", function() {
if (tail) tail.kill(); if (tail) tail.kill();
}); });
} }
RED.nodes.registerType("tail",TailNode); RED.nodes.registerType("tail",TailNode);
}

View File

@ -14,10 +14,10 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var fs = require("fs"); var fs = require("fs");
function FileNode(n) { function FileNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.filename = n.filename; this.filename = n.filename;
@ -58,10 +58,10 @@ function FileNode(n) {
} }
} }
}); });
} }
RED.nodes.registerType("file",FileNode); RED.nodes.registerType("file",FileNode);
function FileInNode(n) { function FileInNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.filename = n.filename; this.filename = n.filename;
@ -86,5 +86,6 @@ function FileInNode(n) {
}); });
} }
}); });
}
RED.nodes.registerType("file in",FileInNode);
} }
RED.nodes.registerType("file in",FileInNode);

View File

@ -14,13 +14,13 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var util = require("util"); var util = require("util");
var redis = require("redis"); var redis = require("redis");
var hashFieldRE = /^([^=]+)=(.*)$/; var hashFieldRE = /^([^=]+)=(.*)$/;
var redisConnectionPool = function() { var redisConnectionPool = function() {
var connections = {}; var connections = {};
var obj = { var obj = {
get: function(host,port) { get: function(host,port) {
@ -51,10 +51,10 @@ var redisConnectionPool = function() {
} }
}; };
return obj; return obj;
}(); }();
function RedisOutNode(n) { function RedisOutNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.port = n.port||"6379"; this.port = n.port||"6379";
this.hostname = n.hostname||"127.0.0.1"; this.hostname = n.hostname||"127.0.0.1";
@ -86,11 +86,12 @@ function RedisOutNode(n) {
} }
} }
}); });
} }
RED.nodes.registerType("redis out",RedisOutNode); RED.nodes.registerType("redis out",RedisOutNode);
RedisOutNode.prototype.close = function() { RedisOutNode.prototype.close = function() {
redisConnectionPool.close(this.client); redisConnectionPool.close(this.client);
}
} }

View File

@ -14,11 +14,11 @@
* limitations under the License. * limitations under the License.
**/ **/
var RED = require(process.env.NODE_RED_HOME+"/red/red"); module.exports = function(RED) {
var mongo = require('mongodb'); var mongo = require('mongodb');
var MongoClient = mongo.MongoClient; var MongoClient = mongo.MongoClient;
function MongoNode(n) { function MongoNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.hostname = n.hostname; this.hostname = n.hostname;
this.port = n.port; this.port = n.port;
@ -37,27 +37,27 @@ function MongoNode(n) {
url += this.hostname+":"+this.port+"/"+this.db; url += this.hostname+":"+this.port+"/"+this.db;
this.url = url; this.url = url;
} }
RED.nodes.registerType("mongodb",MongoNode); RED.nodes.registerType("mongodb",MongoNode);
var querystring = require('querystring'); var querystring = require('querystring');
RED.httpAdmin.get('/mongodb/:id',function(req,res) { RED.httpAdmin.get('/mongodb/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id); var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) { if (credentials) {
res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!="")})); res.send(JSON.stringify({user:credentials.user,hasPassword:(credentials.password&&credentials.password!="")}));
} else { } else {
res.send(JSON.stringify({})); res.send(JSON.stringify({}));
} }
}); });
RED.httpAdmin.delete('/mongodb/:id',function(req,res) { RED.httpAdmin.delete('/mongodb/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id); RED.nodes.deleteCredentials(req.params.id);
res.send(200); res.send(200);
}); });
RED.httpAdmin.post('/mongodb/:id',function(req,res) { RED.httpAdmin.post('/mongodb/:id',function(req,res) {
var body = ""; var body = "";
req.on('data', function(chunk) { req.on('data', function(chunk) {
body+=chunk; body+=chunk;
@ -78,10 +78,10 @@ RED.httpAdmin.post('/mongodb/:id',function(req,res) {
RED.nodes.addCredentials(req.params.id,credentials); RED.nodes.addCredentials(req.params.id,credentials);
res.send(200); res.send(200);
}); });
}); });
function MongoOutNode(n) { function MongoOutNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.collection = n.collection; this.collection = n.collection;
this.mongodb = n.mongodb; this.mongodb = n.mongodb;
@ -131,11 +131,11 @@ function MongoOutNode(n) {
this.clientDb.close(); this.clientDb.close();
} }
}); });
} }
RED.nodes.registerType("mongodb out",MongoOutNode); RED.nodes.registerType("mongodb out",MongoOutNode);
function MongoInNode(n) { function MongoInNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.collection = n.collection; this.collection = n.collection;
this.mongodb = n.mongodb; this.mongodb = n.mongodb;
@ -174,5 +174,6 @@ function MongoInNode(n) {
this.clientDb.close(); this.clientDb.close();
} }
}); });
}
RED.nodes.registerType("mongodb in",MongoInNode);
} }
RED.nodes.registerType("mongodb in",MongoInNode);

View File

@ -54,7 +54,7 @@ function loadNode(nodeDir, nodeFn) {
var r = require(nodeFilename); var r = require(nodeFilename);
if (typeof r === "function") { if (typeof r === "function") {
try { try {
var promise = r(RED); var promise = r(require('../red'));
if (promise != null && typeof promise.then === "function") { if (promise != null && typeof promise.then === "function") {
promise.then(function() { promise.then(function() {
resolve(loadTemplate(templateFilename)); resolve(loadTemplate(templateFilename));