After the io.sockets.clients() method has been depreciated from the later versions of Socket.io, and after my research couldn't find any documentation on the socket.io offical web.
Morever, it gives the type error for clients() method as below:
TypeError: undefined is not a function
Has anyone figured out how to list all the connected clients in a room with the later versions of Socket.io?
You use get(roomId) to get the value of that roomId in a Map and you use . size to the number of elements in a set unlike . length for number of elements in an array.
socket.io rooms are a lightweight data structure. They are simply an array of connections that are associated with that room. You can have as many as you want (within normal memory usage limits). There is no heavyweight thing that makes a room expensive in terms of resources.
You can check the socket.io version in node_modules->socket.io->package. json and there will be "version": "your version of socket.io".
Once you reboot your machine, you will now be able to happily go to 55k concurrent connections (per incoming IP).
To get socket IDs of the clients connected to a room use this code:
var namespace = '/';
var roomName = 'my_room_name';
for (var socketId in io.nsps[namespace].adapter.rooms[roomName]) {
console.log(socketId);
}
Edit:
To get socket by socket ID you may try this:
var socket = io.sockets.connected[socketId];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With