2021-10-12 10:38:49 +02:00
|
|
|
import { IframeApiContribution, sendToWorkadventure, queryWorkadventure } from "./IframeApiContribution";
|
2021-05-28 01:14:10 +02:00
|
|
|
|
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,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-30 10:15:55 +02:00
|
|
|
export class WorkadventureNavigationCommands extends IframeApiContribution<WorkadventureNavigationCommands> {
|
|
|
|
callbacks = [];
|
2021-05-28 01:14:10 +02:00
|
|
|
|
|
|
|
openTab(url: string): void {
|
|
|
|
sendToWorkadventure({
|
2021-06-30 10:15:55 +02:00
|
|
|
type: "openTab",
|
|
|
|
data: {
|
|
|
|
url,
|
|
|
|
},
|
2021-05-28 01:14:10 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
goToPage(url: string): void {
|
|
|
|
sendToWorkadventure({
|
2021-06-30 10:15:55 +02:00
|
|
|
type: "goToPage",
|
|
|
|
data: {
|
|
|
|
url,
|
|
|
|
},
|
2021-05-28 01:14:10 +02:00
|
|
|
});
|
|
|
|
}
|
2021-06-17 11:23:56 +02:00
|
|
|
|
|
|
|
goToRoom(url: string): void {
|
2021-06-17 11:32:59 +02:00
|
|
|
sendToWorkadventure({
|
2021-06-30 10:15:55 +02:00
|
|
|
type: "loadPage",
|
|
|
|
data: {
|
|
|
|
url,
|
|
|
|
},
|
2021-06-17 11:32:59 +02:00
|
|
|
});
|
2021-06-17 11:23:56 +02:00
|
|
|
}
|
2021-06-18 17:22:56 +02:00
|
|
|
|
2022-01-05 10:30:27 +01:00
|
|
|
async openCoWebSite(
|
|
|
|
url: string,
|
|
|
|
allowApi?: boolean,
|
|
|
|
allowPolicy?: string,
|
2022-02-07 14:55:51 +01:00
|
|
|
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,
|
2022-02-07 14:55:51 +01:00
|
|
|
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,
|
|
|
|
});
|
|
|
|
}
|
2021-05-28 01:14:10 +02:00
|
|
|
}
|
|
|
|
|
2021-06-17 11:23:56 +02:00
|
|
|
export default new WorkadventureNavigationCommands();
|