Using Socket.IO v.1.3.5
for node.JS...
How can I get the number of real users (not sessions) that are connected in a room?
Number of sessions:
var room = io.sockets.adapter.rooms[roomId] || {};
var numSocketsInRoom = Object.keys(room).length;
But if the same user is connected in multiple browser tabs, the numSocketInRoom is increased because is the number of sessions, and not the real number of users.
In my case, any socket have the user saved in socket.userId
, but I don't know how indicate this to get the number of users connected in a room...
Thank you!
roomID
, for the users you could also use the same approachvar users = {}
and add the ID-s there. – Risto Novik Oct 12 '15 at 10:55socket.on('disconnect',callback)
– Aral Roca Oct 13 '15 at 9:03