Update node-red-nodes io nodes to use strict and pass jshint scan

This commit is contained in:
Dave C-J
2014-06-28 23:35:33 +01:00
parent 9e0585a721
commit 052a7d587d
4 changed files with 182 additions and 174 deletions

View File

@@ -14,42 +14,44 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
var spawn = require('child_process').spawn;
var plat = require('os').platform();
module.exports = function(RED) {
"use strict";
var spawn = require('child_process').spawn;
var plat = require('os').platform();
function PingNode(n) {
RED.nodes.createNode(this,n);
this.host = n.host;
this.timer = n.timer * 1000;
var node = this;
function PingNode(n) {
RED.nodes.createNode(this,n);
this.host = n.host;
this.timer = n.timer * 1000;
var node = this;
node.tout = setInterval(function() {
var ex;
if (plat == "linux") ex = spawn('ping', ['-n', '-w', '5', '-c', '1', node.host]);
else if (plat.match(/^win/)) ex = spawn('ping', ['-n', '1', '-w', '5000', node.host]);
else if (plat == "darwin") ex = spawn('ping', ['-n', '-t', '5', '-c', '1', node.host]);
else node.error("Sorry - your platform - "+plat+" - is not recognised.");
var res = false;
ex.stdout.on('data', function (data) {
//console.log('[ping] stdout: ' + data.toString());
var regex = /from.*time.(.*)ms/;
var m = regex.exec(data.toString())||"";
if (m != '') { res = Number(m[1]); }
});
ex.stderr.on('data', function (data) {
//console.log('[ping] stderr: ' + data);
});
ex.on('close', function (code) {
//console.log('[ping] result: ' + code);
var msg = { payload:false, topic:node.host };
if (code == 0) msg = { payload:res, topic:node.host };
node.send(msg);
});
}, node.timer);
node.tout = setInterval(function() {
var ex;
if (plat == "linux") { ex = spawn('ping', ['-n', '-w', '5', '-c', '1', node.host]); }
else if (plat.match(/^win/)) { ex = spawn('ping', ['-n', '1', '-w', '5000', node.host]); }
else if (plat == "darwin") { ex = spawn('ping', ['-n', '-t', '5', '-c', '1', node.host]); }
else { node.error("Sorry - your platform - "+plat+" - is not recognised."); }
var res = false;
ex.stdout.on('data', function (data) {
//console.log('[ping] stdout: ' + data.toString());
var regex = /from.*time.(.*)ms/;
var m = regex.exec(data.toString())||"";
if (m !== '') { res = Number(m[1]); }
});
ex.stderr.on('data', function (data) {
//console.log('[ping] stderr: ' + data);
});
ex.on('close', function (code) {
//console.log('[ping] result: ' + code);
var msg = { payload:false, topic:node.host };
if (code === 0) { msg = { payload:res, topic:node.host }; }
node.send(msg);
});
}, node.timer);
this.on("close", function() {
clearInterval(this.tout);
});
this.on("close", function() {
clearInterval(this.tout);
});
}
RED.nodes.registerType("ping",PingNode);
}
RED.nodes.registerType("ping",PingNode);