Alimon Alimon - 1 month ago 6x
Node.js Question

How can I refuse some user joins the same room in

Now I'm using express4 and 0.9 to build online chat room.The problem is I don't want same user join the same room when they open another tab in browser(or other browser).I can get the user session(to visit those room,user must logging in,when they logged,the 'uid' will set into the session).


What is clearly your problem ? You have trouble accessing the current users in a room ? If this is that, you can get the sockets from a room like this and then check for your user.

First add a parameter to your first socket to be able to identify later.


Then, for every connection, check in the sockets of the room if you have already a socket with this session ID

var socketsOfTheRoom = io.sockets.clients(your_room_name);

for(var i=0;i<socketsOfTheRoom.length;i++){
   sock = socketsOfTheRoom[i]
      return true

return false