How to get the Client Count inside a Socket.IO room? Version 3.1.1

In Version 2.x.x it was possible to write

socket.in('room_id').clients((err, clients) => clients.length);

Is there a similar way to this in Version 3.1.1 / 3.x.x?

I know about the join-room and leave-room events, but i hope for a solution without own counting logic.

35 thoughts on “How to get the Client Count inside a Socket.IO room? Version 3.1.1”

  1. After some research i found out they simply renamed it into "allSockets" and changed it a little bit. The new solution now looks like this:

    let length = await socket.in('room_id').allSockets().length;
    
    Reply

Leave a Comment