diff --git a/front/src/Connexion/RoomConnection.ts b/front/src/Connexion/RoomConnection.ts index 3492f0f9..a27bd323 100644 --- a/front/src/Connexion/RoomConnection.ts +++ b/front/src/Connexion/RoomConnection.ts @@ -43,6 +43,7 @@ export class RoomConnection implements RoomConnection { private userId: number|null = null; private listeners: Map = new Map(); private static websocketFactory: null|((url: string)=>any) = null; // eslint-disable-line @typescript-eslint/no-explicit-any + private closed: boolean = false; public static setWebsocketFactory(websocketFactory: (url: string)=>any): void { // eslint-disable-line @typescript-eslint/no-explicit-any RoomConnection.websocketFactory = websocketFactory; @@ -157,6 +158,7 @@ export class RoomConnection implements RoomConnection { public closeConnection(): void { this.socket?.close(); + this.closed = true; } private resolveJoinRoom!: (value?: (RoomJoinedMessageInterface | PromiseLike | undefined)) => void; @@ -389,6 +391,9 @@ export class RoomConnection implements RoomConnection { public onServerDisconnected(callback: (event: CloseEvent) => void): void { this.socket.addEventListener('close', (event) => { + if (this.closed === true) { + return; + } console.log('Socket closed with code '+event.code+". Reason: "+event.reason); if (event.code === 1000) { // Normal closure case diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index bdaf3ac6..608d920b 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -951,7 +951,7 @@ export class GameScene extends Phaser.Scene implements CenterListener { }); const nextSceneKey = this.checkToExit(); - if(nextSceneKey){ + if (nextSceneKey) { // We are completely destroying the current scene to avoid using a half-backed instance when coming back to the same map. this.connection.closeConnection(); this.simplePeer.unregister();