workadventure/back/src/Model/RoomIdentifier.ts

31 lines
1 KiB
TypeScript
Raw Normal View History

//helper functions to parse room IDs
export const isRoomAnonymous = (roomID: string): boolean => {
2021-06-24 10:09:10 +02:00
if (roomID.startsWith("_/")) {
return true;
2021-06-24 10:09:10 +02:00
} else if (roomID.startsWith("@/")) {
return false;
} else {
2021-06-24 10:09:10 +02:00
throw new Error("Incorrect room ID: " + roomID);
}
2021-06-24 10:09:10 +02:00
};
export const extractRoomSlugPublicRoomId = (roomId: string): string => {
2021-06-24 10:09:10 +02:00
const idParts = roomId.split("/");
if (idParts.length < 3) throw new Error("Incorrect roomId: " + roomId);
return idParts.slice(2).join("/");
};
export interface extractDataFromPrivateRoomIdResponse {
organizationSlug: string;
worldSlug: string;
roomSlug: string;
}
export const extractDataFromPrivateRoomId = (roomId: string): extractDataFromPrivateRoomIdResponse => {
2021-06-24 10:09:10 +02:00
const idParts = roomId.split("/");
if (idParts.length < 4) throw new Error("Incorrect roomId: " + roomId);
const organizationSlug = idParts[1];
const worldSlug = idParts[2];
const roomSlug = idParts[3];
2021-06-24 10:09:10 +02:00
return { organizationSlug, worldSlug, roomSlug };
};