workadventure/front/src/Api/iframe/nav.ts

88 lines
2.1 KiB
TypeScript
Raw Normal View History

2021-10-12 10:38:49 +02:00
import { IframeApiContribution, sendToWorkadventure, queryWorkadventure } from "./IframeApiContribution";
2021-10-25 18:42:51 +02:00
export class CoWebsite {
2022-01-05 10:30:27 +01:00
constructor(private readonly id: string) {}
2021-10-25 18:42:51 +02:00
close() {
return queryWorkadventure({
type: "closeCoWebsite",
data: this.id,
});
}
}
export class WorkadventureNavigationCommands extends IframeApiContribution<WorkadventureNavigationCommands> {
callbacks = [];
openTab(url: string): void {
sendToWorkadventure({
type: "openTab",
data: {
url,
},
});
}
goToPage(url: string): void {
sendToWorkadventure({
type: "goToPage",
data: {
url,
},
});
}
goToRoom(url: string): void {
2021-06-17 11:32:59 +02:00
sendToWorkadventure({
type: "loadPage",
data: {
url,
},
2021-06-17 11:32:59 +02:00
});
}
2022-01-05 10:30:27 +01:00
async openCoWebSite(
url: string,
allowApi?: boolean,
allowPolicy?: string,
widthPercent?: number,
2022-01-05 10:30:27 +01:00
position?: number,
closable?: boolean,
lazy?: boolean
): Promise<CoWebsite> {
2021-10-25 18:42:51 +02:00
const result = await queryWorkadventure({
2021-10-12 10:38:49 +02:00
type: "openCoWebsite",
data: {
url,
allowApi,
allowPolicy,
widthPercent,
2021-10-12 10:38:49 +02:00
position,
2022-01-05 10:30:27 +01:00
closable,
lazy,
2021-10-12 10:38:49 +02:00
},
});
2022-01-05 10:30:27 +01:00
return new CoWebsite(result.id);
2021-10-12 10:38:49 +02:00
}
2021-10-25 18:50:40 +02:00
async getCoWebSites(): Promise<CoWebsite[]> {
2021-10-25 18:42:51 +02:00
const result = await queryWorkadventure({
2021-10-12 10:38:49 +02:00
type: "getCoWebsites",
2021-11-24 15:29:12 +01:00
data: undefined,
2021-10-12 10:38:49 +02:00
});
2022-01-05 10:30:27 +01:00
return result.map((cowebsiteEvent) => new CoWebsite(cowebsiteEvent.id));
2021-10-12 10:38:49 +02:00
}
/**
* @deprecated Use closeCoWebsites instead to close all co-websites
*/
closeCoWebSite() {
return queryWorkadventure({
type: "closeCoWebsites",
data: undefined,
});
}
}
export default new WorkadventureNavigationCommands();