From f06abfae4c8edafee31304d3d9ef37823481cc60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 1 Oct 2020 16:51:51 +0200 Subject: [PATCH 1/4] Migrating to uuid v4 --- back/src/Controller/AuthenticateController.ts | 4 ++-- back/src/Controller/FileController.ts | 4 ++-- back/src/Controller/IoSocketController.ts | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/back/src/Controller/AuthenticateController.ts b/back/src/Controller/AuthenticateController.ts index aa27a468..84cfd97f 100644 --- a/back/src/Controller/AuthenticateController.ts +++ b/back/src/Controller/AuthenticateController.ts @@ -1,6 +1,6 @@ import Jwt from "jsonwebtoken"; import {ADMIN_API_TOKEN, ADMIN_API_URL, SECRET_KEY, URL_ROOM_STARTED} from "../Enum/EnvironmentVariable"; //TODO fix import by "_Enum/..." -import { uuid } from 'uuidv4'; +import { v4 } from 'uuid'; import {HttpRequest, HttpResponse, TemplatedApp} from "uWebSockets.js"; import {BaseController} from "./BaseController"; import Axios from "axios"; @@ -63,7 +63,7 @@ export class AuthenticateController extends BaseController { mapUrlStart = data.mapUrlStart; newUrl = this.getNewUrlOnAdminAuth(data) } else { - userUuid = uuid(); + userUuid = v4(); mapUrlStart = host.replace('api.', 'maps.') + URL_ROOM_STARTED; newUrl = null; } diff --git a/back/src/Controller/FileController.ts b/back/src/Controller/FileController.ts index 889cfa61..87b72b80 100644 --- a/back/src/Controller/FileController.ts +++ b/back/src/Controller/FileController.ts @@ -1,6 +1,6 @@ import {App} from "../Server/sifrr.server"; -import {uuid} from "uuidv4"; +import {v4} from "uuid"; import {HttpRequest, HttpResponse} from "uWebSockets.js"; import {BaseController} from "./BaseController"; import { Readable } from 'stream' @@ -51,7 +51,7 @@ export class FileController extends BaseController { }) try { - const audioMessageId = uuid(); + const audioMessageId = v4(); const params = await res.formData({ onFile: (fieldname: string, diff --git a/back/src/Controller/IoSocketController.ts b/back/src/Controller/IoSocketController.ts index 9696748a..e9f97ea6 100644 --- a/back/src/Controller/IoSocketController.ts +++ b/back/src/Controller/IoSocketController.ts @@ -16,7 +16,7 @@ import {PointInterface} from "../Model/Websocket/PointInterface"; import {isWebRtcSignalMessageInterface} from "../Model/Websocket/WebRtcSignalMessage"; import {UserInGroupInterface} from "../Model/Websocket/UserInGroupInterface"; import {isItemEventMessageInterface} from "../Model/Websocket/ItemEventMessage"; -import {uuid} from 'uuidv4'; +import { v4 as uuidv4 } from 'uuid'; import {GroupUpdateInterface} from "_Model/Websocket/GroupUpdateInterface"; import {Movable} from "../Model/Movable"; import { @@ -135,7 +135,7 @@ export class IoSocketController { if (ALLOW_ARTILLERY) { return { token, - userUuid: uuid() + userUuid: uuidv4() } } else { throw new Error("In order to perform a load-testing test on this environment, you must set the ALLOW_ARTILLERY environment variable to 'true'"); From 8bc5832eac2651f2ca2a27c2393971edcb802296 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 1 Oct 2020 17:15:33 +0200 Subject: [PATCH 2/4] Removing warning on startup --- front/src/Connexion/ConnectionManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/front/src/Connexion/ConnectionManager.ts b/front/src/Connexion/ConnectionManager.ts index 4df45099..59a54510 100644 --- a/front/src/Connexion/ConnectionManager.ts +++ b/front/src/Connexion/ConnectionManager.ts @@ -10,7 +10,7 @@ interface LoginApiData { } class ConnectionManager { - private initPromise: Promise = Promise.reject(); + private initPromise!: Promise; private mapUrlStart: string|null = null; private authToken:string|null = null; From e1193ad95aa3c072ac4f45fa39f02d3d1cd637f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 1 Oct 2020 17:16:36 +0200 Subject: [PATCH 3/4] Fixing console removal --- back/src/Model/Group.ts | 3 +-- front/src/Administration/ConsoleGlobalMessageManager.ts | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/back/src/Model/Group.ts b/back/src/Model/Group.ts index 16dd6cd5..a67383f0 100644 --- a/back/src/Model/Group.ts +++ b/back/src/Model/Group.ts @@ -1,7 +1,6 @@ -import { World, ConnectCallback, DisconnectCallback } from "./World"; +import { ConnectCallback, DisconnectCallback } from "./World"; import { User } from "./User"; import {PositionInterface} from "_Model/PositionInterface"; -import {uuid} from "uuidv4"; import {Movable} from "_Model/Movable"; import {PositionNotifier} from "_Model/PositionNotifier"; diff --git a/front/src/Administration/ConsoleGlobalMessageManager.ts b/front/src/Administration/ConsoleGlobalMessageManager.ts index e60b8a3d..135f1799 100644 --- a/front/src/Administration/ConsoleGlobalMessageManager.ts +++ b/front/src/Administration/ConsoleGlobalMessageManager.ts @@ -36,10 +36,8 @@ export class ConsoleGlobalMessageManager { } initialise() { - try { - HtmlUtils.removeElementByIdOrFail(CLASS_CONSOLE_MESSAGE); - }catch (err){ - console.error(err); + for (const elem of document.getElementsByClassName(CLASS_CONSOLE_MESSAGE)) { + elem.remove(); } const typeConsole = document.createElement('input'); From 1061c80f1ff66e9a3b68d61b45e76d9f7e8ded6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Thu, 1 Oct 2020 17:16:49 +0200 Subject: [PATCH 4/4] Fixing connection closing --- front/src/Connexion/RoomConnection.ts | 5 +++++ front/src/Phaser/Game/GameScene.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) 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();