mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add additional safety checks to avoid acting on non-existent objects (#1057)
This commit is contained in:
parent
361ff315e9
commit
eef59fd40e
@ -444,7 +444,7 @@ module.exports = function(RED) {
|
|||||||
//node.log(RED._("tcpin.errors.client-connected"));
|
//node.log(RED._("tcpin.errors.client-connected"));
|
||||||
node.status({fill:"green",shape:"dot",text:"common.status.connected"});
|
node.status({fill:"green",shape:"dot",text:"common.status.connected"});
|
||||||
node.connected = true;
|
node.connected = true;
|
||||||
if (clients[connection_id].client) {
|
if (clients[connection_id] && clients[connection_id].client) {
|
||||||
clients[connection_id].client.write(clients[connection_id].msg.payload);
|
clients[connection_id].client.write(clients[connection_id].msg.payload);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -455,9 +455,11 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
clients[connection_id].client.on('data', function(data) {
|
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;
|
clients[connection_id].msg.payload = data;
|
||||||
node.send(clients[connection_id].msg);
|
node.send(clients[connection_id].msg);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (node.splitc === 0) {
|
else if (node.splitc === 0) {
|
||||||
clients[connection_id].msg.payload = data;
|
clients[connection_id].msg.payload = data;
|
||||||
node.send(clients[connection_id].msg);
|
node.send(clients[connection_id].msg);
|
||||||
@ -523,7 +525,9 @@ module.exports = function(RED) {
|
|||||||
//console.log("END");
|
//console.log("END");
|
||||||
node.connected = false;
|
node.connected = false;
|
||||||
node.status({fill:"grey",shape:"ring",text:"common.status.disconnected"});
|
node.status({fill:"grey",shape:"ring",text:"common.status.disconnected"});
|
||||||
|
if (clients[connection_id] && clients[connection_id].client) {
|
||||||
clients[connection_id].client = null;
|
clients[connection_id].client = null;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
clients[connection_id].client.on('close', function() {
|
clients[connection_id].client.on('close', function() {
|
||||||
@ -537,7 +541,7 @@ module.exports = function(RED) {
|
|||||||
node.connected = false;
|
node.connected = false;
|
||||||
node.status({fill:"red",shape:"ring",text:"common.status.error"});
|
node.status({fill:"red",shape:"ring",text:"common.status.error"});
|
||||||
node.error(RED._("tcpin.errors.connect-fail"),msg);
|
node.error(RED._("tcpin.errors.connect-fail"),msg);
|
||||||
if (clients[connection_id].client) {
|
if (clients[connection_id] && clients[connection_id].client) {
|
||||||
clients[connection_id].client.destroy();
|
clients[connection_id].client.destroy();
|
||||||
delete clients[connection_id];
|
delete clients[connection_id];
|
||||||
}
|
}
|
||||||
@ -547,7 +551,7 @@ module.exports = function(RED) {
|
|||||||
node.connected = false;
|
node.connected = false;
|
||||||
node.status({fill:"grey",shape:"dot",text:"tcpin.errors.connect-timeout"});
|
node.status({fill:"grey",shape:"dot",text:"tcpin.errors.connect-timeout"});
|
||||||
//node.warn(RED._("tcpin.errors.connect-timeout"));
|
//node.warn(RED._("tcpin.errors.connect-timeout"));
|
||||||
if (clients[connection_id].client) {
|
if (clients[connection_id] && clients[connection_id].client) {
|
||||||
clients[connection_id].client.connect(port, host, function() {
|
clients[connection_id].client.connect(port, host, function() {
|
||||||
node.connected = true;
|
node.connected = true;
|
||||||
node.status({fill:"green",shape:"dot",text:"common.status.connected"});
|
node.status({fill:"green",shape:"dot",text:"common.status.connected"});
|
||||||
|
Loading…
Reference in New Issue
Block a user