Correctly cleaning room in pusher even if an exception occurs
Closes #1646 (again)
This commit is contained in:
parent
e0aab9c0ce
commit
d792d35d09
@ -273,7 +273,7 @@ export class IoSocketController {
|
|||||||
rejected: true,
|
rejected: true,
|
||||||
message: err?.response?.data.message,
|
message: err?.response?.data.message,
|
||||||
status: err?.response?.status,
|
status: err?.response?.status,
|
||||||
room,
|
roomId,
|
||||||
},
|
},
|
||||||
websocketKey,
|
websocketKey,
|
||||||
websocketProtocol,
|
websocketProtocol,
|
||||||
@ -368,6 +368,7 @@ export class IoSocketController {
|
|||||||
rejected: true,
|
rejected: true,
|
||||||
reason: e instanceof InvalidTokenError ? tokenInvalidException : null,
|
reason: e instanceof InvalidTokenError ? tokenInvalidException : null,
|
||||||
message: e.message,
|
message: e.message,
|
||||||
|
roomId,
|
||||||
},
|
},
|
||||||
websocketKey,
|
websocketKey,
|
||||||
websocketProtocol,
|
websocketProtocol,
|
||||||
@ -380,6 +381,7 @@ export class IoSocketController {
|
|||||||
rejected: true,
|
rejected: true,
|
||||||
reason: null,
|
reason: null,
|
||||||
message: "500 Internal Server Error",
|
message: "500 Internal Server Error",
|
||||||
|
roomId,
|
||||||
},
|
},
|
||||||
websocketKey,
|
websocketKey,
|
||||||
websocketProtocol,
|
websocketProtocol,
|
||||||
@ -394,9 +396,8 @@ export class IoSocketController {
|
|||||||
open: (ws) => {
|
open: (ws) => {
|
||||||
if (ws.rejected === true) {
|
if (ws.rejected === true) {
|
||||||
// If there is a room in the error, let's check if we need to clean it.
|
// If there is a room in the error, let's check if we need to clean it.
|
||||||
if (ws.room) {
|
if (ws.roomId) {
|
||||||
const room = ws.room as PusherRoom;
|
socketManager.deleteRoomIfEmptyFromId(ws.roomId as string);
|
||||||
socketManager.deleteRoomIfEmpty(room);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//FIX ME to use status code
|
//FIX ME to use status code
|
||||||
|
@ -370,7 +370,7 @@ export class SocketManager implements ZoneEventListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public deleteRoomIfEmpty(room: PusherRoom): void {
|
private deleteRoomIfEmpty(room: PusherRoom): void {
|
||||||
if (room.isEmpty()) {
|
if (room.isEmpty()) {
|
||||||
room.close();
|
room.close();
|
||||||
this.rooms.delete(room.roomUrl);
|
this.rooms.delete(room.roomUrl);
|
||||||
@ -378,6 +378,13 @@ export class SocketManager implements ZoneEventListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public deleteRoomIfEmptyFromId(roomUrl: string): void {
|
||||||
|
const room = this.rooms.get(roomUrl);
|
||||||
|
if (room) {
|
||||||
|
this.deleteRoomIfEmpty(room);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async getOrCreateRoom(roomUrl: string): Promise<PusherRoom> {
|
async getOrCreateRoom(roomUrl: string): Promise<PusherRoom> {
|
||||||
//check and create new world for a room
|
//check and create new world for a room
|
||||||
let room = this.rooms.get(roomUrl);
|
let room = this.rooms.get(roomUrl);
|
||||||
|
Loading…
Reference in New Issue
Block a user