javascript - how to get socket.io number of clients in room? -


my socket.io version 1.3.5

i want number of clients in particular room.

this code.

 socket.on('create or join', function (numclients, room) {             socket.join(room);     }); 

i use code clients in room :

console.log('number of clients',io.sockets.clients(room)); 

to number of clients in room can following:

    function numclientsinroom(namespace, room) {       var clients = io.nsps[namespace].adapter.rooms[room];       return object.keys(clients).length;     } 

this variable clients hold object each client key. number of clients (keys) in object.

if haven't defined namespace default 1 "/".


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -