Jitsi cowebsite close on hangup

This commit is contained in:
Alexis Faizeau 2022-01-18 14:37:35 +01:00
parent a4b4710f87
commit b9ca630a15
2 changed files with 62 additions and 3 deletions

View file

@ -618,6 +618,7 @@ class CoWebsiteManager {
if (coWebsite.jitsi) { if (coWebsite.jitsi) {
const gameScene = gameManager.getCurrentGameScene(); const gameScene = gameManager.getCurrentGameScene();
gameScene.disableMediaBehaviors(); gameScene.disableMediaBehaviors();
jitsiFactory.restart();
} }
this.currentOperationPromise = this.currentOperationPromise this.currentOperationPromise = this.currentOperationPromise
@ -676,7 +677,7 @@ class CoWebsiteManager {
() => () =>
new Promise((resolve) => { new Promise((resolve) => {
if (coWebsite.jitsi) { if (coWebsite.jitsi) {
jitsiFactory.stop(); jitsiFactory.destroy();
const gameScene = gameManager.getCurrentGameScene(); const gameScene = gameManager.getCurrentGameScene();
gameScene.enableMediaBehaviors(); gameScene.enableMediaBehaviors();
} }

View file

@ -7,6 +7,7 @@ interface jitsiConfigInterface {
startWithAudioMuted: boolean; startWithAudioMuted: boolean;
startWithVideoMuted: boolean; startWithVideoMuted: boolean;
prejoinPageEnabled: boolean; prejoinPageEnabled: boolean;
disableDeepLinking: boolean;
} }
interface JitsiOptions { interface JitsiOptions {
@ -40,6 +41,7 @@ const getDefaultConfig = (): jitsiConfigInterface => {
startWithAudioMuted: !get(requestedMicrophoneState), startWithAudioMuted: !get(requestedMicrophoneState),
startWithVideoMuted: !get(requestedCameraState), startWithVideoMuted: !get(requestedCameraState),
prejoinPageEnabled: false, prejoinPageEnabled: false,
disableDeepLinking: false,
}; };
}; };
@ -176,13 +178,23 @@ class JitsiFactory {
const doResolve = (): void => { const doResolve = (): void => {
const iframe = coWebsiteManager.getCoWebsiteBuffer().querySelector<HTMLIFrameElement>('[id*="jitsi" i]'); const iframe = coWebsiteManager.getCoWebsiteBuffer().querySelector<HTMLIFrameElement>('[id*="jitsi" i]');
if (iframe) { if (iframe && this.jitsiApi) {
coWebsiteManager.addCoWebsiteFromIframe(iframe, false, undefined, 0, false, true); const coWebsite = coWebsiteManager.addCoWebsiteFromIframe(iframe, false, undefined, 0, false, true);
this.jitsiApi.addListener("videoConferenceLeft", () => {
this.closeOrUnload(coWebsite);
});
this.jitsiApi.addListener("readyToClose", () => {
this.closeOrUnload(coWebsite);
});
} }
coWebsiteManager.resizeAllIframes(); coWebsiteManager.resizeAllIframes();
}; };
this.jitsiApi = undefined;
options.onload = () => doResolve(); //we want for the iframe to be loaded before triggering animations. options.onload = () => doResolve(); //we want for the iframe to be loaded before triggering animations.
setTimeout(() => doResolve(), 2000); //failsafe in case the iframe is deleted before loading or too long to load setTimeout(() => doResolve(), 2000); //failsafe in case the iframe is deleted before loading or too long to load
this.jitsiApi = new window.JitsiMeetExternalAPI(domain, options); this.jitsiApi = new window.JitsiMeetExternalAPI(domain, options);
@ -192,6 +204,44 @@ class JitsiFactory {
this.jitsiApi.addListener("videoMuteStatusChanged", this.videoCallback); this.jitsiApi.addListener("videoMuteStatusChanged", this.videoCallback);
} }
private closeOrUnload = function (coWebsite: CoWebsite) {
if (coWebsite.closable) {
coWebsiteManager.closeCoWebsite(coWebsite).catch(() => {
console.error("Error during closing a Jitsi Meet");
});
} else {
coWebsiteManager.unloadCoWebsite(coWebsite).catch(() => {
console.error("Error during unloading a Jitsi Meet");
});
}
};
public restart() {
if (!this.jitsiApi) {
return;
}
this.jitsiApi.addListener("audioMuteStatusChanged", this.audioCallback);
this.jitsiApi.addListener("videoMuteStatusChanged", this.videoCallback);
const coWebsite = coWebsiteManager.searchJitsi();
console.log("jitsi api ", this.jitsiApi);
console.log("iframe cowebsite", coWebsite?.iframe);
if (!coWebsite) {
this.destroy();
return;
}
this.jitsiApi.addListener("videoConferenceLeft", () => {
this.closeOrUnload(coWebsite);
});
this.jitsiApi.addListener("readyToClose", () => {
this.closeOrUnload(coWebsite);
});
}
public stop() { public stop() {
if (!this.jitsiApi) { if (!this.jitsiApi) {
return; return;
@ -199,6 +249,14 @@ class JitsiFactory {
this.jitsiApi.removeListener("audioMuteStatusChanged", this.audioCallback); this.jitsiApi.removeListener("audioMuteStatusChanged", this.audioCallback);
this.jitsiApi.removeListener("videoMuteStatusChanged", this.videoCallback); this.jitsiApi.removeListener("videoMuteStatusChanged", this.videoCallback);
}
public destroy() {
if (!this.jitsiApi) {
return;
}
this.stop();
this.jitsiApi?.dispose(); this.jitsiApi?.dispose();
} }