Skip to content

Commit edd56c1

Browse files
authored
add _sessionip of the user connected to a _sessionid (dceejay#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
1 parent d4cdc48 commit edd56c1

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

worldmap.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -229,27 +229,29 @@ module.exports = function(RED) {
229229
var callback = function(client) {
230230
//client.setMaxListeners(0);
231231
clients[client.id] = client;
232+
//get ip of user connected to the _sessionid, check to see if its proxied first
233+
var sessionip = client.headers['x-real-ip'] || client.headers['x-forwarded-for'] || client.remoteAddress;
232234
node.status({fill:"green",shape:"dot",text:"connected "+Object.keys(clients).length,_sessionid:client.id});
233235
client.on('data', function(message) {
234236
message = JSON.parse(message);
235237
if (message.hasOwnProperty("action")) {
236238
if ((node.events === "files") && (message.action === "file")) {
237239
message.content = Buffer.from(message.content.split('base64,')[1], 'base64');
238-
setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id})});
240+
setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id, _sessionip:sessionip})});
239241
}
240242
else if ((node.events === "connect") && (message.action === "connected")) {
241-
setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id})});
243+
setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id, _sessionip:sessionip})});
242244
}
243245
else if (node.events === "all") {
244-
setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id})});
246+
setImmediate(function() {node.send({payload:message, topic:node.path.substr(1), _sessionid:client.id, _sessionip:sessionip})});
245247
}
246248
}
247249
});
248250
client.on('close', function() {
249251
delete clients[client.id];
250252
node.status({fill:"green",shape:"ring",text:"connected "+Object.keys(clients).length,_sessionid:client.id});
251253
if (node.events !== "files") {
252-
node.send({payload:{action:"disconnect", clients:Object.keys(clients).length}, topic:node.path.substr(1), _sessionid:client.id});
254+
node.send({payload:{action:"disconnect", clients:Object.keys(clients).length}, topic:node.path.substr(1), _sessionid:client.id, _sessionip:sessionip});
253255
}
254256
});
255257
}

0 commit comments

Comments
 (0)