是否可以按用户提供的名称列出房间,或者某个端口是否可以在socket.io中搜索房间,并使用户能够命名房间并设置要加入的用户数。 或者socket.io不能做这些事情,如果是这样的话可以做什么替代可以完成这些任务我长期坚持这些问题并希望得到答案。
答案 0 :(得分:0)
Yes what you're trying is possible. The first part about naming rooms is possible directly using the API. You can search the io.nsps['/'].adapter.rooms
object for the same.
To make the user be able to give names to the room, join that user's connection to a new room:
socket.join(roomName);
You can checkout this blog post for more info on how to restrict people in a room.
This is also a useful resource for namespaces and rooms in Socket.IO: https://www.tutorialspoint.com/socket.io/socket.io_rooms.htm