Merge branch 'develop' into windows-focus-blur-camera

This commit is contained in:
Gregoire Parant 2020-11-10 13:07:08 +01:00
commit 694f5d692f
4 changed files with 18 additions and 4 deletions

View File

@ -20,7 +20,7 @@ import {parse} from "query-string";
import {jwtTokenManager} from "../Services/JWTTokenManager"; import {jwtTokenManager} from "../Services/JWTTokenManager";
import {adminApi, CharacterTexture, FetchMemberDataByUuidResponse} from "../Services/AdminApi"; import {adminApi, CharacterTexture, FetchMemberDataByUuidResponse} from "../Services/AdminApi";
import {SocketManager, socketManager} from "../Services/SocketManager"; 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 {clientEventsEmitter} from "../Services/ClientEventsEmitter";
import {ADMIN_API_TOKEN, ADMIN_API_URL} from "../Enum/EnvironmentVariable"; 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? const client = this.initClient(ws); //todo: into the upgrade instead?
socketManager.handleJoinRoom(client); socketManager.handleJoinRoom(client);
resetPing(client); resetPing(client);
refresLogoutTimerOnPong(ws as ExSocketInterface);
//get data information and show messages //get data information and show messages
if (ADMIN_API_URL) { if (ADMIN_API_URL) {
@ -292,6 +293,9 @@ export class IoSocketController {
drain: (ws) => { drain: (ws) => {
console.log('WebSocket backpressure: ' + ws.getBufferedAmount()); console.log('WebSocket backpressure: ' + ws.getBufferedAmount());
}, },
pong(ws) {
refresLogoutTimerOnPong(ws as ExSocketInterface);
},
close: (ws, code, message) => { close: (ws, code, message) => {
const Client = (ws as ExSocketInterface); const Client = (ws as ExSocketInterface);
try { try {

View File

@ -26,6 +26,7 @@ export interface ExSocketInterface extends WebSocket, Identificable {
batchedMessages: BatchMessage; batchedMessages: BatchMessage;
batchTimeout: NodeJS.Timeout|null; batchTimeout: NodeJS.Timeout|null;
pingTimeout: NodeJS.Timeout|null; pingTimeout: NodeJS.Timeout|null;
pongTimeout: NodeJS.Timeout|null;
disconnecting: boolean, disconnecting: boolean,
tags: string[], tags: string[],
textures: CharacterTexture[], textures: CharacterTexture[],

View File

@ -48,3 +48,12 @@ export function emitError(Client: ExSocketInterface, message: string): void {
} }
console.warn(message); console.warn(message);
} }
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);
}

View File

@ -57,7 +57,7 @@ class CoWebsiteManager {
setTimeout(() => { setTimeout(() => {
this.fire(); this.fire();
}, animationTime) }, animationTime)
}); }).catch(() => this.closeCoWebsite());
} }
/** /**
@ -70,7 +70,7 @@ class CoWebsiteManager {
setTimeout(() => { setTimeout(() => {
this.fire(); this.fire();
}, animationTime) }, animationTime)
}); }).catch(() => this.closeCoWebsite());
} }
public closeCoWebsite(): Promise<void> { public closeCoWebsite(): Promise<void> {