Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有办法找到客户加入的房间?
我试图解决的情况如下:人们可以加入不同的房间,但如果有人离开,我想通知房间里的人。我知道我必须在disconnect事件中使用并向那个房间里的所有人发送消息,但是我找不到知道这个人在哪个房间的方法。
disconnect
io.sockets.on('connection', function(client) { client.on('disconnect', function() { // ... }); });
client.rooms会成功的。
client.rooms
注意:请记住,根据文档,
为方便起见,每个套接字都会自动加入由该 ID 标识的房间。
因此,默认情况下,每个套接字至少连接到一个房间。