remove instance, change room url, fix invalid lastRoomUrls

This commit is contained in:
_Bastler 2021-09-20 08:56:14 +02:00
parent ccafaf11e3
commit 6af1651e03
4 changed files with 37 additions and 15 deletions

View File

@ -145,6 +145,7 @@ class ConnectionManager {
await this.checkAuthUserConnexion(); await this.checkAuthUserConnexion();
} catch (err) { } catch (err) {
console.error(err); console.error(err);
await this.anonymousLogin();
} }
} }
this.localUser = localUserStore.getLocalUser() as LocalUser; //if authToken exist in localStorage then localUser cannot be null this.localUser = localUserStore.getLocalUser() as LocalUser; //if authToken exist in localStorage then localUser cannot be null
@ -172,8 +173,13 @@ class ConnectionManager {
} }
//get detail map for anonymous login and set texture in local storage //get detail map for anonymous login and set texture in local storage
this._currentRoom = await Room.createRoom(new URL(roomPath)); try {
if (this._currentRoom.textures != undefined && this._currentRoom.textures.length > 0) { this._currentRoom = await Room.createRoom(new URL(roomPath));
} catch (e) {
console.error(e);
localUserStore.setLastRoomUrl(null);
}
if (this._currentRoom != undefined && this._currentRoom.textures != undefined && this._currentRoom.textures.length > 0) {
//check if texture was changed //check if texture was changed
if (this.localUser.textures.length === 0) { if (this.localUser.textures.length === 0) {
this.localUser.textures = this._currentRoom.textures; this.localUser.textures = this._currentRoom.textures;
@ -201,6 +207,7 @@ class ConnectionManager {
} }
public async anonymousLogin(isBenchmark: boolean = false): Promise<void> { public async anonymousLogin(isBenchmark: boolean = false): Promise<void> {
localUserStore.setAuthToken(null);
try { try {
const data = await Axios.post(`${PUSHER_URL}/anonymLogin`).then((res) => res.data); const data = await Axios.post(`${PUSHER_URL}/anonymLogin`).then((res) => res.data);
this.localUser = new LocalUser(data.userUuid, []); this.localUser = new LocalUser(data.userUuid, []);

View File

@ -120,12 +120,19 @@ class LocalUserStore {
return localStorage.getItem(fullscreenKey) === "true"; return localStorage.getItem(fullscreenKey) === "true";
} }
setLastRoomUrl(roomUrl: string): void { setLastRoomUrl(roomUrl: string | null): void {
localStorage.setItem(lastRoomUrl, roomUrl.toString()); if (roomUrl) {
caches.open(cacheAPIIndex).then((cache) => { localStorage.setItem(lastRoomUrl, roomUrl.toString());
const stringResponse = new Response(JSON.stringify({ roomUrl })); caches.open(cacheAPIIndex).then((cache) => {
cache.put(`/${lastRoomUrl}`, stringResponse); const stringResponse = new Response(JSON.stringify({ roomUrl }));
}); cache.put(`/${lastRoomUrl}`, stringResponse);
});
} else {
localStorage.removeItem(lastRoomUrl);
caches.open(cacheAPIIndex).then((cache) => {
cache.delete(`/${lastRoomUrl}`);
});
}
} }
getLastRoomUrl(): string { getLastRoomUrl(): string {
return ( return (

View File

@ -18,7 +18,7 @@ export class Room {
private _iframeAuthentication?: string; private _iframeAuthentication?: string;
private _mapUrl: string | undefined; private _mapUrl: string | undefined;
private _textures: CharacterTexture[] | undefined; private _textures: CharacterTexture[] | undefined;
private instance: string | undefined; // private instance: string | undefined;
private readonly _search: URLSearchParams; private readonly _search: URLSearchParams;
private constructor(private roomUrl: URL) { private constructor(private roomUrl: URL) {
@ -73,12 +73,13 @@ export class Room {
const baseUrl = new URL(currentRoomUrl); const baseUrl = new URL(currentRoomUrl);
const currentRoom = new Room(baseUrl); const currentRoom = new Room(baseUrl);
let instance: string = "global"; // let instance: string = "global";
if (currentRoom.isPublic) { // if (currentRoom.isPublic) {
instance = currentRoom.instance as string; // instance = currentRoom.instance as string;
} //}
baseUrl.pathname = "/_/" + instance + "/" + absoluteExitSceneUrl.host + absoluteExitSceneUrl.pathname; // baseUrl.pathname = "/_/" + instance + "/" + absoluteExitSceneUrl.host + absoluteExitSceneUrl.pathname;
baseUrl.pathname = "/_/" + absoluteExitSceneUrl.host + absoluteExitSceneUrl.pathname;
if (absoluteExitSceneUrl.hash) { if (absoluteExitSceneUrl.hash) {
baseUrl.hash = absoluteExitSceneUrl.hash; baseUrl.hash = absoluteExitSceneUrl.hash;
} }
@ -114,6 +115,8 @@ export class Room {
* - In a private URL: [organizationId/worldId] * - In a private URL: [organizationId/worldId]
*/ */
public getInstance(): string { public getInstance(): string {
return "";
/*
if (this.instance !== undefined) { if (this.instance !== undefined) {
return this.instance; return this.instance;
} }
@ -129,6 +132,7 @@ export class Room {
this.instance = match[1] + "/" + match[2]; this.instance = match[1] + "/" + match[2];
return this.instance; return this.instance;
} }
*/
} }
/** /**

View File

@ -94,7 +94,7 @@ import { userIsAdminStore } from "../../Stores/GameStore";
import { layoutManagerActionStore } from "../../Stores/LayoutManagerStore"; import { layoutManagerActionStore } from "../../Stores/LayoutManagerStore";
import { EmbeddedWebsiteManager } from "./EmbeddedWebsiteManager"; import { EmbeddedWebsiteManager } from "./EmbeddedWebsiteManager";
import { GameMapPropertiesListener } from "./GameMapPropertiesListener"; import { GameMapPropertiesListener } from "./GameMapPropertiesListener";
import {analyticsClient} from "../../Administration/AnalyticsClient"; import { analyticsClient } from "../../Administration/AnalyticsClient";
import { get } from "svelte/store"; import { get } from "svelte/store";
export interface GameSceneInitInterface { export interface GameSceneInitInterface {
@ -300,6 +300,10 @@ export class GameScene extends DirtyScene {
//remove loader in progress //remove loader in progress
removeLoader(this); removeLoader(this);
if (this.roomUrl == localUserStore.getLastRoomUrl()) {
localUserStore.setLastRoomUrl(null);
}
//display an error scene //display an error scene
this.scene.start(ErrorSceneName, { this.scene.start(ErrorSceneName, {
title: "Network error", title: "Network error",