add _sessionip of the user connected to a _sessionid (#163)
* add _sessionip of the user connected to a _sessionid ![https://i.ibb.co/GM3yFxv/sessionip.jpg](https://i.ibb.co/GM3yFxv/sessionip.jpg) * forgot the disconnect section
This commit is contained in:
parent
d4cdc48a2f
commit
edd56c122a
10
worldmap.js
10
worldmap.js
@ -229,19 +229,21 @@ module.exports = function(RED) {
|
|||||||
var callback = function(client) {
|
var callback = function(client) {
|
||||||
//client.setMaxListeners(0);
|
//client.setMaxListeners(0);
|
||||||
clients[client.id] = client;
|
clients[client.id] = client;
|
||||||
|
//get ip of user connected to the _sessionid, check to see if its proxied first
|
||||||
|
var sessionip = client.headers['x-real-ip'] || client.headers['x-forwarded-for'] || client.remoteAddress;
|
||||||
node.status({fill:"green",shape:"dot",text:"connected "+Object.keys(clients).length,_sessionid:client.id});
|
node.status({fill:"green",shape:"dot",text:"connected "+Object.keys(clients).length,_sessionid:client.id});
|
||||||
client.on('data', function(message) {
|
client.on('data', function(message) {
|
||||||
message = JSON.parse(message);
|
message = JSON.parse(message);
|
||||||
if (message.hasOwnProperty("action")) {
|
if (message.hasOwnProperty("action")) {
|
||||||
if ((node.events === "files") && (message.action === "file")) {
|
if ((node.events === "files") && (message.action === "file")) {
|
||||||
message.content = Buffer.from(message.content.split('base64,')[1], 'base64');
|
message.content = Buffer.from(message.content.split('base64,')[1], 'base64');
|
||||||
setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id})});
|
setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id, _sessionip:sessionip})});
|
||||||
}
|
}
|
||||||
else if ((node.events === "connect") && (message.action === "connected")) {
|
else if ((node.events === "connect") && (message.action === "connected")) {
|
||||||
setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id})});
|
setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id, _sessionip:sessionip})});
|
||||||
}
|
}
|
||||||
else if (node.events === "all") {
|
else if (node.events === "all") {
|
||||||
setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id})});
|
setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id, _sessionip:sessionip})});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -249,7 +251,7 @@ module.exports = function(RED) {
|
|||||||
delete clients[client.id];
|
delete clients[client.id];
|
||||||
node.status({fill:"green",shape:"ring",text:"connected "+Object.keys(clients).length,_sessionid:client.id});
|
node.status({fill:"green",shape:"ring",text:"connected "+Object.keys(clients).length,_sessionid:client.id});
|
||||||
if (node.events !== "files") {
|
if (node.events !== "files") {
|
||||||
node.send({payload:{action:"disconnect", clients:Object.keys(clients).length}, topic:node.path.substr(1), _sessionid:client.id});
|
node.send({payload:{action:"disconnect", clients:Object.keys(clients).length}, topic:node.path.substr(1), _sessionid:client.id, _sessionip:sessionip});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user