From 1781b8423cefde9d49f54c2f0006366d2e3d78d0 Mon Sep 17 00:00:00 2001 From: Alban Bruder Date: Tue, 12 Apr 2022 12:56:48 -0400 Subject: [PATCH] Replace Room.getInstance with getter function --- front/src/Connexion/Room.ts | 40 +++++++++--------------------- front/src/Phaser/Game/GameScene.ts | 2 +- 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/front/src/Connexion/Room.ts b/front/src/Connexion/Room.ts index a3be5f53..a79e2604 100644 --- a/front/src/Connexion/Room.ts +++ b/front/src/Connexion/Room.ts @@ -22,7 +22,7 @@ export class Room { private _authenticationMandatory: boolean = DISABLE_ANONYMOUS; private _iframeAuthentication?: string = OPID_LOGIN_SCREEN_PROVIDER; private _mapUrl: string | undefined; - private instance: string | undefined; + private _instance: string | undefined; private readonly _search: URLSearchParams; private _contactPage: string | undefined; private _group: string | null = null; @@ -85,7 +85,9 @@ export class Room { const currentRoom = new Room(baseUrl); let instance: string = "global"; if (currentRoom.isPublic) { - instance = currentRoom.getInstance(); + const match = /[_*]\/([^/]+)\/.+/.exec(currentRoom.id); + if (!match) throw new Error('Could not extract instance from "' + currentRoom.id + '"'); + instance = match[1]; } baseUrl.pathname = "/_/" + instance + "/" + absoluteExitSceneUrl.host + absoluteExitSceneUrl.pathname; @@ -130,7 +132,7 @@ export class Room { this._canReport = data.canReport ?? false; this._loadingLogo = data.loadingLogo ?? undefined; this._loginSceneLogo = data.loginSceneLogo ?? undefined; - this.instance = data.instance; + this._instance = data.instance; return new MapDetail(data.mapUrl); } else { console.log(data); @@ -152,31 +154,6 @@ export class Room { } } - /** - * Instance name is: - * - In a public URL: the second part of the URL ( _/[instance]/map.json) - * - In a private URL: [organizationId/worldId] - * - * @deprecated - */ - public getInstance(): string { - if (this.instance !== undefined) { - return this.instance; - } - - if (this.isPublic) { - const match = /[_*]\/([^/]+)\/.+/.exec(this.id); - if (!match) throw new Error('Could not extract instance from "' + this.id + '"'); - this.instance = match[1]; - return this.instance; - } else { - const match = /@\/([^/]+)\/([^/]+)\/.+/.exec(this.id); - if (!match) throw new Error('Could not extract instance from "' + this.id + '"'); - this.instance = match[1] + "/" + match[2]; - return this.instance; - } - } - public isDisconnected(): boolean { const alone = this._search.get("alone"); if (alone && alone !== "0" && alone.toLowerCase() !== "false") { @@ -234,6 +211,13 @@ export class Room { return this._group; } + get instance(): string { + if (!this._instance) { + throw new Error("Instance not fetched yet"); + } + return this._instance; + } + get expireOn(): Date | undefined { return this._expireOn; } diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index ab8f572c..ffef7588 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -234,7 +234,7 @@ export class GameScene extends DirtyScene { }); this.Terrains = []; this.groups = new Map(); - this.instance = room.getInstance(); + this.instance = room.instance; this.MapUrlFile = MapUrlFile; this.roomUrl = room.key;