https://stackoverflow.com/a/6727354/462608
The short answer:
io.sockets.adapter.roomsI analysed io:
The sockets output part from io as shown in that answer contains the following:
JavaScript
x
8
1
sockets:
2
{ manager: [Circular],
3
name: '',
4
sockets: { '210837319844898486': [Object] },
5
auth: false,
6
flags: { endpoint: '', exceptions: [] },
7
_events: { connection: [Function] } },
8
Where is the adapter
? Where are the rooms
?
What is the way to find out adapter and rooms from the output of io
?
Advertisement
Answer
I think you are trying to get room before joining it. First You have to Join room and than you can get the rooms in io.sockets.adapter.rooms
You can checkout this link to know rooms
JavaScript
1
16
16
1
let room_id = 111
2
3
io.sockets.on("connection", function (socket) {
4
// Everytime a client logs in, display a connected message
5
console.log("Server-Client Connected!");
6
socket.join("_room" + room_id);
7
socket.on('connected', function (data) {
8
9
});
10
console.log(io.sockets.adapter.rooms);
11
socket.on('qr_code_scan', function (room_id) {
12
io.sockets.in("_room" + room_id).emit("qr_code_scan", true);
13
});
14
});
15
16
Log of io.sockets.adapter.rooms
JavaScript
1
16
16
1
{bjYiUV5YZy54VedKAAAA: Room, _room111: Room}
2
app.js:55
3
_room111:Room {sockets: {…}, length: 1}
4
length:1
5
sockets:{-isBAZIB-Sm3jArgAAAB: true}
6
-isBAZIB-Sm3jArgAAAB:true
7
__proto__:Object
8
__proto__:Object
9
-isBAZIB-Sm3jArgAAAB:Room {sockets: {…}, length: 1}
10
length:1
11
sockets:{-isBAZIB-Sm3jArgAAAB: true}
12
-isBAZIB-Sm3jArgAAAB:true
13
__proto__:Object
14
__proto__:Object
15
__proto__:Object
16