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:
sockets: { manager: [Circular], name: '', sockets: { '210837319844898486': [Object] }, auth: false, flags: { endpoint: '', exceptions: [] }, _events: { connection: [Function] } },
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
let room_id = 111 io.sockets.on("connection", function (socket) { // Everytime a client logs in, display a connected message console.log("Server-Client Connected!"); socket.join("_room" + room_id); socket.on('connected', function (data) { }); console.log(io.sockets.adapter.rooms); socket.on('qr_code_scan', function (room_id) { io.sockets.in("_room" + room_id).emit("qr_code_scan", true); }); });
Log of io.sockets.adapter.rooms
{bjYiUV5YZy54VedKAAAA: Room, _room111: Room} app.js:55 _room111:Room {sockets: {…}, length: 1} length:1 sockets:{-isBAZIB-Sm3jArgAAAB: true} -isBAZIB-Sm3jArgAAAB:true __proto__:Object __proto__:Object -isBAZIB-Sm3jArgAAAB:Room {sockets: {…}, length: 1} length:1 sockets:{-isBAZIB-Sm3jArgAAAB: true} -isBAZIB-Sm3jArgAAAB:true __proto__:Object __proto__:Object __proto__:Object