如何在socket.io 1.0中获得会议室的客户列表
我可以在socket.io 0.9中使用此代码获取会议室的客户列表.
I can get room's clients list with this code in socket.io 0.9.
io.sockets.clients(roomName)
如何在socket.io 1.0中做到这一点?
How can I do this in socket.io 1.0?
Consider this rather more complete answer linked in a comment above on the question: https://stackoverflow.com/a/24425207/1449799
一个房间中的客户可以在
The clients in a room can be found at
io.nsps[yourNamespace].adapter.rooms[roomName]
这是一个关联数组,其键为套接字ID.在我们的案例中,我们想知道一个房间中的客户数量,因此我们做了Object.keys(io.nsps[yourNamespace].adapter.rooms[roomName]).length
This is an associative array with keys that are socket ids. In our case, we wanted to know the number of clients in a room, so we did Object.keys(io.nsps[yourNamespace].adapter.rooms[roomName]).length
如果您还没有看到/使用过命名空间(例如这个家伙[me]),则可以在这里 http://socket.io/docs/rooms-and-namespaces/ (重要的是:默认名称空间是'/')
In case you haven't seen/used namespaces (like this guy[me]), you can learn about them here http://socket.io/docs/rooms-and-namespaces/ (importantly: the default namespace is '/')
已更新(尤其是@Zettam):
Updated (esp. for @Zettam):
查看此仓库以查看其工作原理: https://github.com/thegreatmichael/socket -io-clients
checkout this repo to see this working: https://github.com/thegreatmichael/socket-io-clients