ihatecsv ihatecsv - 7 months ago 18
Javascript Question

How do I add a socket.io socket to a room via their socketid?

I'm running a function with this line I pilfered from the internet somewhere:

io.sockets[socketID].join(roomName);


It isn't working properly. Is there any way I can accomplish adding a socket to a room without having reference to the socket object? Or is there any way to get a reference to the socket object from an ID?

Thanks!

Answer

In socket.io 1+, you would use the socket id on the server like this:

io.sockets.connected[socketID].join(roomName);