Wednesday, 15 April 2015

javascript - (number of) clients connected to a room in socket.io -



javascript - (number of) clients connected to a room in socket.io -

i've been struggling find efficient way number of clients conencted room in socket.io. i've been advised thread: how room's clients list in socket.io 1.0 none of solutions work in thread besides 1 checks every single conencted socket , rooms able display single room's cliens.

therefore, need inquire 1 time more: (urrently) efficient way (number of) clients in room in socket.io?

io.nsps[yournamespace].adapter.rooms[roomname] // default namespace '/'

returns object of clients boolean value or undefined if there no clients. in of cases can length of object

object.keys(io.nsps[yournamespace].adapter.rooms[roomname]).length

but work if there @ to the lowest degree 1 client connected, due undefined returned.

if you're not using specific namespace, can utilize io.sockets.adapter.rooms[roomname] instead.

by default, when client disconnects, leaves room, way has worked me.

javascript node.js socket.io

No comments:

Post a Comment