diff --git a/back/src/Controller/IoSocketController.ts b/back/src/Controller/IoSocketController.ts index a27d91df..c71edd86 100644 --- a/back/src/Controller/IoSocketController.ts +++ b/back/src/Controller/IoSocketController.ts @@ -20,7 +20,7 @@ import {parse} from "query-string"; import {jwtTokenManager} from "../Services/JWTTokenManager"; import {adminApi, CharacterTexture, FetchMemberDataByUuidResponse} from "../Services/AdminApi"; import {SocketManager, socketManager} from "../Services/SocketManager"; -import {emitInBatch, resetPing} from "../Services/IoSocketHelpers"; +import {emitInBatch, pongMaxInterval, refresLogoutTimerOnPong, resetPing} from "../Services/IoSocketHelpers"; import {clientEventsEmitter} from "../Services/ClientEventsEmitter"; import {ADMIN_API_TOKEN, ADMIN_API_URL} from "../Enum/EnvironmentVariable"; @@ -240,6 +240,7 @@ export class IoSocketController { const client = this.initClient(ws); //todo: into the upgrade instead? socketManager.handleJoinRoom(client); resetPing(client); + refresLogoutTimerOnPong(ws as ExSocketInterface); //get data information and show messages if (ADMIN_API_URL) { @@ -292,6 +293,9 @@ export class IoSocketController { drain: (ws) => { console.log('WebSocket backpressure: ' + ws.getBufferedAmount()); }, + pong(ws) { + refresLogoutTimerOnPong(ws as ExSocketInterface); + }, close: (ws, code, message) => { const Client = (ws as ExSocketInterface); try { diff --git a/back/src/Model/Websocket/ExSocketInterface.ts b/back/src/Model/Websocket/ExSocketInterface.ts index 205032bc..e3d19138 100644 --- a/back/src/Model/Websocket/ExSocketInterface.ts +++ b/back/src/Model/Websocket/ExSocketInterface.ts @@ -26,6 +26,7 @@ export interface ExSocketInterface extends WebSocket, Identificable { batchedMessages: BatchMessage; batchTimeout: NodeJS.Timeout|null; pingTimeout: NodeJS.Timeout|null; + pongTimeout: NodeJS.Timeout|null; disconnecting: boolean, tags: string[], textures: CharacterTexture[], diff --git a/back/src/Services/IoSocketHelpers.ts b/back/src/Services/IoSocketHelpers.ts index 2166a53e..acaa0bb9 100644 --- a/back/src/Services/IoSocketHelpers.ts +++ b/back/src/Services/IoSocketHelpers.ts @@ -47,4 +47,13 @@ export function emitError(Client: ExSocketInterface, message: string): void { Client.send(serverToClientMessage.serializeBinary().buffer, true); } console.warn(message); -} \ No newline at end of file +} + +export const pongMaxInterval = 30000; // the maximum duration (in ms) between pongs before we shutdown the connexion. + +export function refresLogoutTimerOnPong(ws: ExSocketInterface): void { + if(ws.pongTimeout) clearTimeout(ws.pongTimeout); + ws.pongTimeout = setTimeout(() => { + ws.close(); + }, pongMaxInterval); +} diff --git a/front/src/WebRtc/CoWebsiteManager.ts b/front/src/WebRtc/CoWebsiteManager.ts index ab63e60a..46d03702 100644 --- a/front/src/WebRtc/CoWebsiteManager.ts +++ b/front/src/WebRtc/CoWebsiteManager.ts @@ -57,7 +57,7 @@ class CoWebsiteManager { setTimeout(() => { this.fire(); }, animationTime) - }); + }).catch(() => this.closeCoWebsite()); } /** @@ -70,7 +70,7 @@ class CoWebsiteManager { setTimeout(() => { this.fire(); }, animationTime) - }); + }).catch(() => this.closeCoWebsite()); } public closeCoWebsite(): Promise {