mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
merge from upstream
This commit is contained in:
commit
b81f251023
@ -25,7 +25,7 @@ function FunctionNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.name = n.name;
|
||||
this.func = n.func;
|
||||
var functionText = "var results = (function(msg){"+this.func+"})(msg);";
|
||||
var functionText = "var results = (function(msg){"+this.func+"\n})(msg);";
|
||||
this.topic = n.topic;
|
||||
this.context = {global:RED.settings.functionGlobalContext || {}};
|
||||
try {
|
||||
|
@ -16,12 +16,11 @@
|
||||
|
||||
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
||||
var reconnectTime = RED.settings.socketReconnectTime||10000;
|
||||
var socketTimeout = RED.settings.socketTimeout||null;
|
||||
var net = require('net');
|
||||
|
||||
var connectionPool = {};
|
||||
|
||||
|
||||
|
||||
function TcpIn(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.host = n.host;
|
||||
@ -83,7 +82,6 @@ function TcpIn(n) {
|
||||
buffer = null;
|
||||
}
|
||||
});
|
||||
|
||||
client.on('close', function() {
|
||||
delete connectionPool[id];
|
||||
node.log("connection lost to "+node.host+":"+node.port);
|
||||
@ -91,7 +89,6 @@ function TcpIn(n) {
|
||||
reconnectTimeout = setTimeout(setupTcpClient, reconnectTime);
|
||||
}
|
||||
});
|
||||
|
||||
client.on('error', function(err) {
|
||||
node.log(err);
|
||||
});
|
||||
@ -105,6 +102,7 @@ function TcpIn(n) {
|
||||
});
|
||||
} else {
|
||||
var server = net.createServer(function (socket) {
|
||||
if (socketTimeout !== null) { socket.setTimeout(socketTimeout); }
|
||||
var id = (1+Math.random()*4294967295).toString(16);
|
||||
connectionPool[id] = socket;
|
||||
|
||||
@ -145,6 +143,10 @@ function TcpIn(n) {
|
||||
buffer = null;
|
||||
}
|
||||
});
|
||||
socket.on('timeout', function() {
|
||||
node.log('timeout closed socket port '+node.port);
|
||||
socket.end();
|
||||
});
|
||||
socket.on('close', function() {
|
||||
delete connectionPool[id];
|
||||
});
|
||||
@ -163,7 +165,6 @@ function TcpIn(n) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
RED.nodes.registerType("tcp in",TcpIn);
|
||||
|
||||
function TcpOut(n) {
|
||||
@ -187,14 +188,11 @@ function TcpOut(n) {
|
||||
connected = true;
|
||||
node.log("connected to "+node.host+":"+node.port);
|
||||
});
|
||||
|
||||
client.on('error', function (err) {
|
||||
node.log('error : '+err);
|
||||
});
|
||||
|
||||
client.on('end', function (err) {
|
||||
});
|
||||
|
||||
client.on('close', function() {
|
||||
node.log("connection lost to "+node.host+":"+node.port);
|
||||
connected = false;
|
||||
@ -206,7 +204,6 @@ function TcpOut(n) {
|
||||
}
|
||||
setupTcpClient();
|
||||
|
||||
|
||||
node.on("input", function(msg) {
|
||||
if (connected && msg.payload != null) {
|
||||
if (Buffer.isBuffer(msg.payload)) {
|
||||
@ -243,9 +240,14 @@ function TcpOut(n) {
|
||||
} else {
|
||||
var connectedSockets = [];
|
||||
var server = net.createServer(function (socket) {
|
||||
if (socketTimeout !== null) { socket.setTimeout(socketTimeout); }
|
||||
var remoteDetails = socket.remoteAddress+":"+socket.remotePort;
|
||||
node.log("connection from "+remoteDetails);
|
||||
connectedSockets.push(socket);
|
||||
socket.on('timeout', function() {
|
||||
node.log('timeout closed socket port '+node.port);
|
||||
socket.end();
|
||||
});
|
||||
socket.on('close',function() {
|
||||
node.log("connection closed from "+remoteDetails);
|
||||
connectedSockets.splice(connectedSockets.indexOf(socket),1);
|
||||
@ -254,7 +256,6 @@ function TcpOut(n) {
|
||||
node.log("socket error from "+remoteDetails);
|
||||
connectedSockets.splice(connectedSockets.indexOf(socket),1);
|
||||
});
|
||||
|
||||
});
|
||||
node.on("input", function(msg) {
|
||||
if (msg.payload != null) {
|
||||
@ -283,5 +284,3 @@ function TcpOut(n) {
|
||||
}
|
||||
|
||||
RED.nodes.registerType("tcp out",TcpOut);
|
||||
|
||||
|
||||
|
@ -283,10 +283,12 @@ RED.app.get('/twitter/:id/auth', function(req, res){
|
||||
oauth_callback: req.query.callback
|
||||
},function(error, oauth_token, oauth_token_secret, results){
|
||||
if (error) {
|
||||
console.log(error);
|
||||
res.send("yeah no. didn't work.")
|
||||
}
|
||||
else {
|
||||
var resp = '<h2>Oh no!</h2>'+
|
||||
'<p>Something went wrong with the authentication process. The following error was returned:<p>'+
|
||||
'<p><b>'+error.statusCode+'</b>: '+error.data+'</p>'+
|
||||
'<p>One known cause of this type of failure is if the clock is wrong on system running Node-RED.';
|
||||
res.send(resp)
|
||||
} else {
|
||||
credentials.oauth_token = oauth_token;
|
||||
credentials.oauth_token_secret = oauth_token_secret;
|
||||
res.redirect('https://twitter.com/oauth/authorize?oauth_token='+oauth_token)
|
||||
|
@ -31,6 +31,10 @@ module.exports = {
|
||||
// Retry time in milliseconds for TCP socket connections
|
||||
//socketReconnectTime: 10000,
|
||||
|
||||
// Timeout in milliseconds for TCP server socket connections
|
||||
// defaults to no timeout
|
||||
//socketTimeout: 120000,
|
||||
|
||||
// Maximum number of lines in debug window before pruning
|
||||
debugMaxLength: 1000,
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user