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

yet more JShint cleaning.

This commit is contained in:
Dave C-J 2014-07-18 21:49:48 +01:00
parent 252135532d
commit 4770a06679
4 changed files with 29 additions and 20 deletions

View File

@ -30,7 +30,7 @@ module.exports = function(RED) {
var urlencParser = express.urlencoded(); var urlencParser = express.urlencoded();
function rawBodyParser(req, res, next) { 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;
getBody(req, { getBody(req, {
@ -38,7 +38,7 @@ module.exports = function(RED) {
length: req.headers['content-length'], length: req.headers['content-length'],
encoding: 'utf8' encoding: 'utf8'
}, function (err, buf) { }, function (err, buf) {
if (err) return next(err); if (err) { return next(err); }
req.body = buf; req.body = buf;
next(); next();
}); });
@ -95,10 +95,10 @@ module.exports = function(RED) {
} }
} }
if (RED.settings.httpNodeCors) { if (RED.settings.httpNodeCors) {
var routes = RED.httpNode.routes['options']; var route = RED.httpNode.route['options'];
for (var i = 0; i<routes.length; i++) { for (var j = 0; j<route.length; j++) {
if (routes[i].path == this.url) { if (route[j].path == this.url) {
routes.splice(i,1); route.splice(j,1);
//break; //break;
} }
} }
@ -166,7 +166,7 @@ module.exports = function(RED) {
opts.method = method; opts.method = method;
opts.headers = {}; opts.headers = {};
if (msg.headers) { if (msg.headers) {
for (var v in msg.headers) { for (var v = 0; v < msg.headers.length; v++) {
opts.headers[v.toLowerCase()] = msg.headers[v]; opts.headers[v.toLowerCase()] = msg.headers[v];
} }
} }
@ -226,7 +226,7 @@ module.exports = function(RED) {
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({}));
} }

View File

@ -75,7 +75,7 @@ module.exports = function(RED) {
// Workaround https://github.com/einaros/ws/pull/253 // Workaround https://github.com/einaros/ws/pull/253
// Remove listeners from RED.server // Remove listeners from RED.server
var listener = null; var listener = null;
for(var event in node._serverListeners){ for (var event = 0; event < node._serverListeners.length; event++) {
listener = node._serverListeners[event]; listener = node._serverListeners[event];
if(typeof listener === "function"){ if(typeof listener === "function"){
RED.server.removeListener(event,listener); RED.server.removeListener(event,listener);
@ -115,15 +115,19 @@ module.exports = function(RED) {
} }
WebSocketListenerNode.prototype.broadcast = function(data){ WebSocketListenerNode.prototype.broadcast = function(data){
for(var i in this.server.clients){ for (var i = 0; i < this.server.clients.length; i++) {
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); try {
session.send(data);
}
catch(e) { // swallow any errors
}
} }
} }
@ -167,7 +171,7 @@ module.exports = function(RED) {
node.serverConfig.send(msg._session.id,payload); node.serverConfig.send(msg._session.id,payload);
} else { } else {
node.serverConfig.broadcast(payload,function(error){ node.serverConfig.broadcast(payload,function(error){
if(!!error){ if (!!error) {
node.warn("An error occurred while sending:" + inspect(error)); node.warn("An error occurred while sending:" + inspect(error));
} }
}); });

View File

@ -24,7 +24,7 @@ module.exports = function(RED) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.files = n.files.split(","); this.files = n.files.split(",");
for (var f in this.files) { for (var f =0; f < this.files.length; f++) {
this.files[f] = this.files[f].trim(); this.files[f] = this.files[f].trim();
} }
this.p = (this.files.length == 1) ? this.files[0] : JSON.stringify(this.files); this.p = (this.files.length == 1) ? this.files[0] : JSON.stringify(this.files);

View File

@ -61,7 +61,7 @@ module.exports = function(RED) {
if (typeof payload === "object") { if (typeof payload === "object") {
payload = JSON.stringify(payload); payload = JSON.stringify(payload);
} else { } else {
payload = new String(payload); payload = payload.toString();
} }
payload += node.addCh; payload += node.addCh;
} else if (node.addCh !== "") { } else if (node.addCh !== "") {
@ -115,15 +115,16 @@ module.exports = function(RED) {
this.serialConfig.newline this.serialConfig.newline
); );
var splitc;
if (node.serialConfig.newline.substr(0,2) == "0x") { if (node.serialConfig.newline.substr(0,2) == "0x") {
var splitc = new Buffer([parseInt(node.serialConfig.newline)]); splitc = new Buffer([parseInt(node.serialConfig.newline)]);
} else { } else {
var splitc = new Buffer(node.serialConfig.newline.replace("\\n","\n").replace("\\r","\r").replace("\\t","\t").replace("\\e","\e").replace("\\f","\f").replace("\\0","\0")); splitc = new Buffer(node.serialConfig.newline.replace("\\n","\n").replace("\\r","\r").replace("\\t","\t").replace("\\e","\e").replace("\\f","\f").replace("\\0","\0"));
} }
this.port.on('data', function(msg) { this.port.on('data', function(msg) {
// single char buffer // single char buffer
if ((node.serialConfig.newline == 0)||(node.serialConfig.newline == "")) { if ((node.serialConfig.newline === 0)||(node.serialConfig.newline === "")) {
if (node.serialConfig.bin !== "bin") { node.send({"payload": String.fromCharCode(msg)}); } if (node.serialConfig.bin !== "bin") { node.send({"payload": String.fromCharCode(msg)}); }
else { node.send({"payload": new Buffer([msg])}); } else { node.send({"payload": new Buffer([msg])}); }
} }
@ -222,7 +223,7 @@ module.exports = function(RED) {
parity: parity, parity: parity,
stopbits: stopbits, stopbits: stopbits,
parser: serialp.parsers.raw parser: serialp.parsers.raw
},true, function(err, results) { if (err) obj.serial.emit('error',err); }); },true, function(err, results) { if (err) { obj.serial.emit('error',err); } });
//} //}
//else { //else {
// obj.serial = new serialp.SerialPort(port,{ // obj.serial = new serialp.SerialPort(port,{
@ -267,6 +268,9 @@ module.exports = function(RED) {
// obj._emitter.emit('data',d); // obj._emitter.emit('data',d);
//} //}
}); });
obj.serial.on("disconnect",function() {
node.warn("Serial Port gone away.");
});
} }
setupSerial(); setupSerial();
return obj; return obj;
@ -285,7 +289,8 @@ module.exports = function(RED) {
util.log("[serial] serial port closed"); util.log("[serial] serial port closed");
done(); done();
}); });
} catch(err) { }; }
catch(err) { }
delete connections[port]; delete connections[port];
} else { } else {
done(); done();