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

@ -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);