Properly delete rooms in Pusher in case of connection error and empty room

Closes #1646
This commit is contained in:
David Négrier 2021-12-20 14:12:58 +01:00
parent 404404d2bf
commit e0aab9c0ce
2 changed files with 17 additions and 6 deletions

View file

@ -351,11 +351,7 @@ export class SocketManager implements ZoneEventListener {
debug("Leaving room %s.", socket.roomId);
room.leave(socket);
if (room.isEmpty()) {
room.close();
this.rooms.delete(socket.roomId);
debug("Room %s is empty. Deleting.", socket.roomId);
}
this.deleteRoomIfEmpty(room);
} else {
console.error("Could not find the GameRoom the user is leaving!");
}
@ -374,6 +370,14 @@ export class SocketManager implements ZoneEventListener {
}
}
public deleteRoomIfEmpty(room: PusherRoom): void {
if (room.isEmpty()) {
room.close();
this.rooms.delete(room.roomUrl);
debug("Room %s is empty. Deleting.", room.roomUrl);
}
}
async getOrCreateRoom(roomUrl: string): Promise<PusherRoom> {
//check and create new world for a room
let room = this.rooms.get(roomUrl);