2020-11-25 17:17:48 +01:00
|
|
|
import {Room} from "../Connexion/Room";
|
2020-10-12 16:23:07 +02:00
|
|
|
|
|
|
|
export enum GameConnexionTypes {
|
|
|
|
anonymous=1,
|
|
|
|
organization,
|
|
|
|
register,
|
2020-10-13 17:20:20 +02:00
|
|
|
empty,
|
2020-10-12 16:23:07 +02:00
|
|
|
unknown,
|
|
|
|
}
|
|
|
|
|
|
|
|
//this class is responsible with analysing and editing the game's url
|
|
|
|
class UrlManager {
|
2020-10-12 18:59:49 +02:00
|
|
|
|
2020-10-12 16:23:07 +02:00
|
|
|
//todo: use that to detect if we can find a token in localstorage
|
|
|
|
public getGameConnexionType(): GameConnexionTypes {
|
|
|
|
const url = window.location.pathname.toString();
|
2020-10-13 15:55:30 +02:00
|
|
|
if (url.includes('_/')) {
|
2020-10-12 16:23:07 +02:00
|
|
|
return GameConnexionTypes.anonymous;
|
2020-10-13 15:55:30 +02:00
|
|
|
} else if (url.includes('@/')) {
|
2020-10-12 16:23:07 +02:00
|
|
|
return GameConnexionTypes.organization;
|
2020-10-13 15:55:30 +02:00
|
|
|
} else if(url.includes('register/')) {
|
2020-10-13 17:20:20 +02:00
|
|
|
return GameConnexionTypes.register;
|
|
|
|
} else if(url === '/') {
|
|
|
|
return GameConnexionTypes.empty;
|
2020-10-12 16:23:07 +02:00
|
|
|
} else {
|
2020-10-13 17:20:20 +02:00
|
|
|
return GameConnexionTypes.unknown;
|
2020-10-12 16:23:07 +02:00
|
|
|
}
|
|
|
|
}
|
2020-10-12 18:59:49 +02:00
|
|
|
|
2020-10-12 16:23:07 +02:00
|
|
|
public getOrganizationToken(): string|null {
|
|
|
|
const match = /\/register\/(.+)/.exec(window.location.pathname.toString());
|
|
|
|
return match ? match [1] : null;
|
|
|
|
}
|
|
|
|
|
2020-11-25 17:17:48 +01:00
|
|
|
public pushRoomIdToUrl(room:Room): void {
|
2021-01-21 09:40:11 +01:00
|
|
|
if (window.location.pathname === room.id) return;
|
2020-11-25 17:17:48 +01:00
|
|
|
const hash = window.location.hash;
|
|
|
|
history.pushState({}, 'WorkAdventure', room.id+hash);
|
|
|
|
}
|
2021-01-21 09:40:11 +01:00
|
|
|
|
2020-11-19 14:32:18 +01:00
|
|
|
public getStartLayerNameFromUrl(): string|null {
|
2020-11-19 17:06:28 +01:00
|
|
|
const hash = window.location.hash;
|
2020-11-19 14:32:18 +01:00
|
|
|
return hash.length > 1 ? hash.substring(1) : null;
|
2020-11-18 18:15:57 +01:00
|
|
|
}
|
2020-10-12 18:59:49 +02:00
|
|
|
|
2020-11-19 14:32:18 +01:00
|
|
|
pushStartLayerNameToUrl(startLayerName: string): void {
|
|
|
|
window.location.hash = startLayerName;
|
|
|
|
}
|
2020-10-12 16:23:07 +02:00
|
|
|
}
|
|
|
|
|
2020-10-12 18:59:49 +02:00
|
|
|
export const urlManager = new UrlManager();
|