4d4f845b9e
Turning the "importsNotUsedAsValues" TS config value to "error". This will require us to use `import type` instead of `import` when we are importing a value that is only used as a type (and therefore that is dropped by the Typescript compiler). Why this change? This is a requirement to be able to use Svelte in the future. See https://github.com/sveltejs/svelte-preprocess/issues/206#issuecomment-663193798
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import type {Room} from "../Connexion/Room";
|
|
|
|
export enum GameConnexionTypes {
|
|
anonymous=1,
|
|
organization,
|
|
register,
|
|
empty,
|
|
unknown,
|
|
}
|
|
|
|
//this class is responsible with analysing and editing the game's url
|
|
class UrlManager {
|
|
|
|
//todo: use that to detect if we can find a token in localstorage
|
|
public getGameConnexionType(): GameConnexionTypes {
|
|
const url = window.location.pathname.toString();
|
|
if (url.includes('_/')) {
|
|
return GameConnexionTypes.anonymous;
|
|
} else if (url.includes('@/')) {
|
|
return GameConnexionTypes.organization;
|
|
} else if(url.includes('register/')) {
|
|
return GameConnexionTypes.register;
|
|
} else if(url === '/') {
|
|
return GameConnexionTypes.empty;
|
|
} else {
|
|
return GameConnexionTypes.unknown;
|
|
}
|
|
}
|
|
|
|
public getOrganizationToken(): string|null {
|
|
const match = /\/register\/(.+)/.exec(window.location.pathname.toString());
|
|
return match ? match [1] : null;
|
|
}
|
|
|
|
public pushRoomIdToUrl(room:Room): void {
|
|
if (window.location.pathname === room.id) return;
|
|
const hash = window.location.hash;
|
|
const search = room.search.toString();
|
|
history.pushState({}, 'WorkAdventure', room.id+(search?'?'+search:'')+hash);
|
|
}
|
|
|
|
public getStartLayerNameFromUrl(): string|null {
|
|
const hash = window.location.hash;
|
|
return hash.length > 1 ? hash.substring(1) : null;
|
|
}
|
|
|
|
pushStartLayerNameToUrl(startLayerName: string): void {
|
|
window.location.hash = startLayerName;
|
|
}
|
|
}
|
|
|
|
export const urlManager = new UrlManager();
|