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

77 lines
1.9 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 {
constructor(private readonly id: string, public readonly position: number) {}
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
});
}
2021-10-25 18:50:40 +02:00
async openCoWebSite(url: string, allowApi?: boolean, allowPolicy?: string, position?: number): 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,
position,
},
});
2021-10-25 18:42:51 +02:00
return new CoWebsite(result.id, result.position);
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
});
2021-10-25 18:42:51 +02:00
return result.map((cowebsiteEvent) => new CoWebsite(cowebsiteEvent.id, cowebsiteEvent.position));
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();