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-10-13 16:42:05 +02:00
|
|
|
//todo: simply use the roomId
|
|
|
|
//todo: test this with cypress
|
2020-10-12 16:23:07 +02:00
|
|
|
public editUrlForRoom(roomSlug: string, organizationSlug: string|null, worldSlug: string |null): string {
|
|
|
|
let newUrl:string;
|
|
|
|
if (organizationSlug) {
|
|
|
|
newUrl = '/@/'+organizationSlug+'/'+worldSlug+'/'+roomSlug;
|
|
|
|
} else {
|
|
|
|
newUrl = '/_/global/'+roomSlug;
|
|
|
|
}
|
|
|
|
history.pushState({}, 'WorkAdventure', newUrl);
|
|
|
|
return newUrl;
|
|
|
|
}
|
2020-11-18 18:15:57 +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();
|