mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add _session and event to WS/TCP Status messages
This commit is contained in:
parent
8fb6bc059e
commit
19a103d3a0
@ -72,19 +72,19 @@ module.exports = function(RED) {
|
|||||||
var id = (1+Math.random()*4294967295).toString(16);
|
var id = (1+Math.random()*4294967295).toString(16);
|
||||||
if (node.isServer) {
|
if (node.isServer) {
|
||||||
node._clients[id] = socket;
|
node._clients[id] = socket;
|
||||||
node.emit('opened',Object.keys(node._clients).length);
|
node.emit('opened',{count:Object.keys(node._clients).length,id:id});
|
||||||
}
|
}
|
||||||
socket.on('open',function() {
|
socket.on('open',function() {
|
||||||
if (!node.isServer) {
|
if (!node.isServer) {
|
||||||
node.emit('opened','');
|
node.emit('opened',{count:'',id:id});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
socket.on('close',function() {
|
socket.on('close',function() {
|
||||||
if (node.isServer) {
|
if (node.isServer) {
|
||||||
delete node._clients[id];
|
delete node._clients[id];
|
||||||
node.emit('closed',Object.keys(node._clients).length);
|
node.emit('closed',{count:Object.keys(node._clients).length,id:id});
|
||||||
} else {
|
} else {
|
||||||
node.emit('closed');
|
node.emit('closed',{count:'',id:id});
|
||||||
}
|
}
|
||||||
if (!node.closing && !node.isServer) {
|
if (!node.closing && !node.isServer) {
|
||||||
clearTimeout(node.tout);
|
clearTimeout(node.tout);
|
||||||
@ -95,7 +95,7 @@ module.exports = function(RED) {
|
|||||||
node.handleEvent(id,socket,'message',data,flags);
|
node.handleEvent(id,socket,'message',data,flags);
|
||||||
});
|
});
|
||||||
socket.on('error', function(err) {
|
socket.on('error', function(err) {
|
||||||
node.emit('erro');
|
node.emit('erro',{err:err,id:id});
|
||||||
if (!node.closing && !node.isServer) {
|
if (!node.closing && !node.isServer) {
|
||||||
clearTimeout(node.tout);
|
clearTimeout(node.tout);
|
||||||
node.tout = setTimeout(function() { startconn(); }, 3000); // try to reconnect every 3 secs... bit fast ?
|
node.tout = setTimeout(function() { startconn(); }, 3000); // try to reconnect every 3 secs... bit fast ?
|
||||||
@ -230,14 +230,30 @@ module.exports = function(RED) {
|
|||||||
if (this.serverConfig) {
|
if (this.serverConfig) {
|
||||||
this.serverConfig.registerInputNode(this);
|
this.serverConfig.registerInputNode(this);
|
||||||
// TODO: nls
|
// TODO: nls
|
||||||
this.serverConfig.on('opened', function(n) { node.status({fill:"green",shape:"dot",text:RED._("websocket.status.connected",{count:n})}); });
|
this.serverConfig.on('opened', function(event) {
|
||||||
this.serverConfig.on('erro', function() { node.status({fill:"red",shape:"ring",text:"common.status.error"}); });
|
node.status({
|
||||||
this.serverConfig.on('closed', function(n) {
|
fill:"green",shape:"dot",text:RED._("websocket.status.connected",{count:event.count}),
|
||||||
if (n > 0) {
|
event:"connect",
|
||||||
node.status({fill:"green",shape:"dot",text:RED._("websocket.status.connected",{count:n})});
|
_session: {type:"websocket",id:event.id}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
this.serverConfig.on('erro', function(event) {
|
||||||
|
node.status({
|
||||||
|
fill:"red",shape:"ring",text:"common.status.error",
|
||||||
|
event:"error",
|
||||||
|
_session: {type:"websocket",id:event.id}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
this.serverConfig.on('closed', function(event) {
|
||||||
|
var status;
|
||||||
|
if (event.count > 0) {
|
||||||
|
status = {fill:"green",shape:"dot",text:RED._("websocket.status.connected",{count:event.count})};
|
||||||
} else {
|
} else {
|
||||||
node.status({fill:"red",shape:"ring",text:"common.status.disconnected"});
|
status = {fill:"red",shape:"ring",text:"common.status.disconnected"};
|
||||||
}
|
}
|
||||||
|
status.event = "disconnect";
|
||||||
|
status._session = {type:"websocket",id:event.id}
|
||||||
|
node.status(status);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this.error(RED._("websocket.errors.missing-conf"));
|
this.error(RED._("websocket.errors.missing-conf"));
|
||||||
@ -261,11 +277,30 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// TODO: nls
|
// TODO: nls
|
||||||
this.serverConfig.on('opened', function(n) { node.status({fill:"green",shape:"dot",text:RED._("websocket.status.connected",{count:n})}); });
|
this.serverConfig.on('opened', function(event) {
|
||||||
this.serverConfig.on('erro', function() { node.status({fill:"red",shape:"ring",text:"common.status.error"}); });
|
node.status({
|
||||||
this.serverConfig.on('closed', function(n) {
|
fill:"green",shape:"dot",text:RED._("websocket.status.connected",{count:event.count}),
|
||||||
if (n > 0) { node.status({fill:"green",shape:"dot",text:RED._("websocket.status.connected",{count:n})}); }
|
event:"connect",
|
||||||
else { node.status({fill:"red",shape:"ring",text:"common.status.disconnected"}); }
|
_session: {type:"websocket",id:event.id}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
this.serverConfig.on('erro', function(event) {
|
||||||
|
node.status({
|
||||||
|
fill:"red",shape:"ring",text:"common.status.error",
|
||||||
|
event:"error",
|
||||||
|
_session: {type:"websocket",id:event.id}
|
||||||
|
})
|
||||||
|
});
|
||||||
|
this.serverConfig.on('closed', function(event) {
|
||||||
|
var status;
|
||||||
|
if (event.count > 0) {
|
||||||
|
status = {fill:"green",shape:"dot",text:RED._("websocket.status.connected",{count:event.count})};
|
||||||
|
} else {
|
||||||
|
status = {fill:"red",shape:"ring",text:"common.status.disconnected"};
|
||||||
|
}
|
||||||
|
status.event = "disconnect";
|
||||||
|
status._session = {type:"websocket",id:event.id}
|
||||||
|
node.status(status);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
|
@ -158,7 +158,13 @@ module.exports = function(RED) {
|
|||||||
var fromp;
|
var fromp;
|
||||||
connectionPool[id] = socket;
|
connectionPool[id] = socket;
|
||||||
count++;
|
count++;
|
||||||
node.status({text:RED._("tcpin.status.connections",{count:count})});
|
node.status({
|
||||||
|
text:RED._("tcpin.status.connections",{count:count}),
|
||||||
|
event:"connect",
|
||||||
|
ip:socket.remoteAddress,
|
||||||
|
port:socket.remotePort,
|
||||||
|
_session: {type:"tcp",id:id}
|
||||||
|
});
|
||||||
|
|
||||||
var buffer = (node.datatype == 'buffer') ? Buffer.alloc(0) : "";
|
var buffer = (node.datatype == 'buffer') ? Buffer.alloc(0) : "";
|
||||||
socket.on('data', function (data) {
|
socket.on('data', function (data) {
|
||||||
@ -209,7 +215,14 @@ module.exports = function(RED) {
|
|||||||
socket.on('close', function() {
|
socket.on('close', function() {
|
||||||
delete connectionPool[id];
|
delete connectionPool[id];
|
||||||
count--;
|
count--;
|
||||||
node.status({text:RED._("tcpin.status.connections",{count:count})});
|
node.status({
|
||||||
|
text:RED._("tcpin.status.connections",{count:count}),
|
||||||
|
event:"disconnect",
|
||||||
|
ip:socket.remoteAddress,
|
||||||
|
port:socket.remotePort,
|
||||||
|
_session: {type:"tcp",id:id}
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
socket.on('error',function(err) {
|
socket.on('error',function(err) {
|
||||||
node.log(err);
|
node.log(err);
|
||||||
|
Loading…
Reference in New Issue
Block a user