Background: I’m making an extremely basic multiplayer online game server where each game is contained in it’s own room and its game data (including its room name) in a GAMES array and I want to remove the game data from the array when the room no longer exists.
I’m hoping theres something like this tht
socket.io.rooms.on('disconnect', function(roomID){
//PSEUDO CODE//
//delete GAMES.getby(gameID:roomID)//
});
Otherwise I plan on looping through the games array and comparing the room names against io.sockets.manager.rooms data when a socket disconnects and deleting any inconsistencies. But I’m sure there must be a more elegant solution.
io.sockets.clients('room')will give you a list of sockets currently in a room, so you could do something like:Hope that helps!