简体   繁体   English

如何获取 Socket.IO 房间内的客户端计数? 版本 3.1.1

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

In Version 2.xx it was possible to write在版本 2.xx 中可以编写

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

Is there a similar way to this in Version 3.1.1 / 3.xx?在 3.1.1 / 3.xx 版本中是否有类似的方法?

I know about the join-room and leave-room events, but i hope for a solution without own counting logic.我知道加入房间和离开房间的事件,但我希望有一个没有自己计数逻辑的解决方案。

After some research i found out they simply renamed it into "allSockets" and changed it a little bit.经过一番研究,我发现他们只是将其重命名为“allSockets”并进行了一些更改。 The new solution now looks like this:新的解决方案现在看起来像这样:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM