mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Resync with master
This commit is contained in:
@@ -36,6 +36,7 @@ module.exports = function(RED) {
|
||||
node.closing = false;
|
||||
|
||||
function startconn() { // Connect to remote endpoint
|
||||
node.tout = null;
|
||||
var socket = new ws(node.path);
|
||||
socket.setMaxListeners(0);
|
||||
node.server = socket; // keep for closing
|
||||
@@ -52,6 +53,7 @@ module.exports = function(RED) {
|
||||
if (node.isServer) { delete node._clients[id]; node.emit('closed',Object.keys(node._clients).length); }
|
||||
else { node.emit('closed'); }
|
||||
if (!node.closing && !node.isServer) {
|
||||
clearTimeout(node.tout);
|
||||
node.tout = setTimeout(function() { startconn(); }, 3000); // try to reconnect every 3 secs... bit fast ?
|
||||
}
|
||||
});
|
||||
@@ -61,6 +63,7 @@ module.exports = function(RED) {
|
||||
socket.on('error', function(err) {
|
||||
node.emit('erro');
|
||||
if (!node.closing && !node.isServer) {
|
||||
clearTimeout(node.tout);
|
||||
node.tout = setTimeout(function() { startconn(); }, 3000); // try to reconnect every 3 secs... bit fast ?
|
||||
}
|
||||
});
|
||||
@@ -123,7 +126,10 @@ module.exports = function(RED) {
|
||||
else {
|
||||
node.closing = true;
|
||||
node.server.close();
|
||||
if (node.tout) { clearTimeout(node.tout); }
|
||||
if (node.tout) {
|
||||
clearTimeout(node.tout);
|
||||
node.tout = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -205,7 +211,9 @@ module.exports = function(RED) {
|
||||
this.error(RED._("websocket.errors.missing-conf"));
|
||||
}
|
||||
this.on('close', function() {
|
||||
node.serverConfig.removeInputNode(node);
|
||||
if (node.serverConfig) {
|
||||
node.serverConfig.removeInputNode(node);
|
||||
}
|
||||
node.status({});
|
||||
});
|
||||
}
|
||||
@@ -217,7 +225,7 @@ module.exports = function(RED) {
|
||||
this.server = (n.client)?n.client:n.server;
|
||||
this.serverConfig = RED.nodes.getNode(this.server);
|
||||
if (!this.serverConfig) {
|
||||
this.error(RED._("websocket.errors.missing-conf"));
|
||||
return this.error(RED._("websocket.errors.missing-conf"));
|
||||
}
|
||||
else {
|
||||
// TODO: nls
|
||||
|
@@ -444,7 +444,7 @@ module.exports = function(RED) {
|
||||
//node.log(RED._("tcpin.errors.client-connected"));
|
||||
node.status({fill:"green",shape:"dot",text:"common.status.connected"});
|
||||
if (clients[connection_id] && clients[connection_id].client) {
|
||||
clients[connection_id].connected = true;
|
||||
clients[connection_id].connected = true;
|
||||
clients[connection_id].client.write(clients[connection_id].msg.payload);
|
||||
}
|
||||
});
|
||||
@@ -454,10 +454,10 @@ module.exports = function(RED) {
|
||||
}
|
||||
|
||||
clients[connection_id].client.on('data', function(data) {
|
||||
if (node.out == "sit") { // if we are staying connected just send the buffer
|
||||
if (node.out === "sit") { // if we are staying connected just send the buffer
|
||||
if (clients[connection_id]) {
|
||||
clients[connection_id].msg.payload = data;
|
||||
node.send(clients[connection_id].msg);
|
||||
node.send(RED.util.cloneMessage(clients[connection_id].msg));
|
||||
}
|
||||
}
|
||||
else if (node.splitc === 0) {
|
||||
@@ -533,7 +533,7 @@ module.exports = function(RED) {
|
||||
//console.log("END");
|
||||
node.status({fill:"grey",shape:"ring",text:"common.status.disconnected"});
|
||||
if (clients[connection_id] && clients[connection_id].client) {
|
||||
clients[connection_id].connected = false;
|
||||
clients[connection_id].connected = false;
|
||||
clients[connection_id].client = null;
|
||||
}
|
||||
});
|
||||
@@ -541,7 +541,7 @@ module.exports = function(RED) {
|
||||
clients[connection_id].client.on('close', function() {
|
||||
//console.log("CLOSE");
|
||||
if (clients[connection_id]) {
|
||||
clients[connection_id].connected = false;
|
||||
clients[connection_id].connected = false;
|
||||
}
|
||||
|
||||
var anyConnected = false;
|
||||
|
Reference in New Issue
Block a user