Replace Room.getInstance with getter function

This commit is contained in:
Alban Bruder 2022-04-12 12:56:48 -04:00 committed by David Négrier
parent 6a202fff49
commit 1781b8423c
2 changed files with 13 additions and 29 deletions

View File

@ -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;
}

View File

@ -234,7 +234,7 @@ export class GameScene extends DirtyScene {
});
this.Terrains = [];
this.groups = new Map<number, Sprite>();
this.instance = room.getInstance();
this.instance = room.instance;
this.MapUrlFile = MapUrlFile;
this.roomUrl = room.key;