Merge pull request #1659 from thecodingmachine/fix/room_cleanup_on_error
Properly delete rooms in Pusher in case of connection error and empty room
This commit is contained in:
commit
7938a7d610
pusher/src
@ -1,5 +1,5 @@
|
||||
import { CharacterLayer, ExSocketInterface } from "../Model/Websocket/ExSocketInterface"; //TODO fix import by "_Model/.."
|
||||
import { GameRoomPolicyTypes } from "../Model/PusherRoom";
|
||||
import { GameRoomPolicyTypes, PusherRoom } from "../Model/PusherRoom";
|
||||
import { PointInterface } from "../Model/Websocket/PointInterface";
|
||||
import {
|
||||
SetPlayerDetailsMessage,
|
||||
@ -273,6 +273,7 @@ export class IoSocketController {
|
||||
rejected: true,
|
||||
message: err?.response?.data.message,
|
||||
status: err?.response?.status,
|
||||
room,
|
||||
},
|
||||
websocketKey,
|
||||
websocketProtocol,
|
||||
@ -392,6 +393,12 @@ export class IoSocketController {
|
||||
/* Handlers */
|
||||
open: (ws) => {
|
||||
if (ws.rejected === true) {
|
||||
// If there is a room in the error, let's check if we need to clean it.
|
||||
if (ws.room) {
|
||||
const room = ws.room as PusherRoom;
|
||||
socketManager.deleteRoomIfEmpty(room);
|
||||
}
|
||||
|
||||
//FIX ME to use status code
|
||||
if (ws.reason === tokenInvalidException) {
|
||||
socketManager.emitTokenExpiredMessage(ws);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user