Move CoWebsite to generic class
This commit is contained in:
parent
f5f71f32ee
commit
7b6a3949bc
12 changed files with 508 additions and 349 deletions
61
front/src/WebRtc/CoWebsite/JitsiCoWebsite.ts
Normal file
61
front/src/WebRtc/CoWebsite/JitsiCoWebsite.ts
Normal file
|
@ -0,0 +1,61 @@
|
|||
import CancelablePromise from "cancelable-promise";
|
||||
import { gameManager } from "../../Phaser/Game/GameManager";
|
||||
import { coWebsiteManager } from "../CoWebsiteManager";
|
||||
import { jitsiFactory } from "../JitsiFactory";
|
||||
import { SimpleCoWebsite } from "./SimpleCoWebsite";
|
||||
|
||||
export class JitsiCoWebsite extends SimpleCoWebsite {
|
||||
private jitsiLoadPromise?: CancelablePromise<HTMLIFrameElement>;
|
||||
|
||||
constructor(url: URL, allowApi?: boolean, allowPolicy?: string, widthPercent?: number, closable?: boolean) {
|
||||
const coWebsite = coWebsiteManager.searchJitsi();
|
||||
|
||||
if (coWebsite) {
|
||||
coWebsiteManager.closeCoWebsite(coWebsite);
|
||||
}
|
||||
|
||||
super(url, allowApi, allowPolicy, widthPercent, closable);
|
||||
}
|
||||
|
||||
setJitsiLoadPromise(promise: CancelablePromise<HTMLIFrameElement>): void {
|
||||
this.jitsiLoadPromise = promise;
|
||||
}
|
||||
|
||||
load(): CancelablePromise<HTMLIFrameElement> {
|
||||
return new CancelablePromise((resolve, reject, cancel) => {
|
||||
this.state.set("loading");
|
||||
|
||||
gameManager.getCurrentGameScene().disableMediaBehaviors();
|
||||
jitsiFactory.restart();
|
||||
|
||||
if (!this.jitsiLoadPromise) {
|
||||
return reject("Undefined Jitsi start callback");
|
||||
}
|
||||
|
||||
const jitsiLoading = this.jitsiLoadPromise
|
||||
.then((iframe) => {
|
||||
this.iframe = iframe;
|
||||
this.iframe.classList.add("pixel");
|
||||
this.state.set("ready");
|
||||
return resolve(iframe);
|
||||
})
|
||||
.catch((err) => {
|
||||
return reject(err);
|
||||
});
|
||||
|
||||
cancel(() => {
|
||||
jitsiLoading.cancel();
|
||||
this.unload().catch((err) => {
|
||||
console.error("Cannot unload Jitsi co-website while cancel loading", err);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
unload(): Promise<void> {
|
||||
jitsiFactory.destroy();
|
||||
gameManager.getCurrentGameScene().enableMediaBehaviors();
|
||||
|
||||
return super.unload();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue