get rooms socket io code example
Example 1: rooms in socket io
io.on('connection', socket => {
socket.join('some room');
});
io.to('some room').emit('some event');
io.to('room1').to('room2').to('room3').emit('some event');
io.on('connection', function(socket){
socket.to('some room').emit('some event');
});
Example 2: socket io get user rooms
function getUserRooms(socket) {
return Object.entries(rooms).reduce((names, [name, room]) => {
if (room.users[socket.id] != null) names.push(name)
return names
}, [])
}