socket.io get rooms which socket is currently in

前端 未结 12 1217
臣服心动
臣服心动 2020-12-14 08:40

Is it possible to get rooms which socket is currently in, without calling

io.sockets.clients(roomName)

for every room name and looking for

12条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-14 08:56

    Version 1.7.3, socket.rooms contains socket.id, so remove it and get the list of rooms:

    Object.keys(socket.rooms).filter(item => item!=socket.id);
    

    In other version, you can print the socket and find the rooms.

提交回复
热议问题