Is it possible to get rooms which socket is currently in, without calling
io.sockets.clients(roomName)
for every room name and looking for
With 3.x
Socket.rooms is Set
now, which means that values in the rooms may only occur once.
Structure example: Set(4) {"
io.on("connect", (socket) => {
console.log(socket.rooms); // Set { }
socket.join("room1");
console.log(socket.rooms); // Set { , "room1" }
});
To check for specific room:
socket.rooms.has("room1"); // true
More about Set and available methods: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
Migration Docs: https://socket.io/docs/migrating-from-2-x-to-3-0/