socketio无法创建空间

I am trying to dynamically create a room. I get an id which will be the name of the room. In the callback I see list of rooms using io.sockets.adapter.rooms and I don't see the room I joined.

io.of('/chat').on('connection', (socket) => {
 const socketQuery = socket.handshake.query;
 if(socketQuery.action === 'createRoom' && socketQuery.doctorUserId){

   console.log("Creating room", socketQuery.doctorUserId);
   socket.join("A ROOM", () => console.log(io.sockets.adapter.rooms)); //I want the id here to be the name of the room
}

我试图只给出一些文本(A ROOM),但在回调中仍然看不到房间名称。

我在console.log中看到了这一点:

Creating room 5e972498125a3d1488d0985f { 'tHlX-TYkQeVlxEB9AAAA': Room { sockets: { 'tHlX-TYkQeVlxEB9AAAA': true }, length: 1 } } Creating room 5e972498125a3d1488d0985f { pZe_38mllgVtSUfrAAAB: Room { sockets: { pZe_38mllgVtSUfrAAAB: true }, length: 1 }, '7oZdWV9mwvuhnvQTAAAC': Room { sockets: { '7oZdWV9mwvuhnvQTAAAC': true }, length: 1 } }

评论