All promises are now handled
This commit is contained in:
parent
6e27ffb2d5
commit
24baf5664c
21 changed files with 262 additions and 208 deletions
|
@ -149,7 +149,7 @@ class CoWebsiteManager {
|
|||
}
|
||||
|
||||
buttonCloseCoWebsites.blur();
|
||||
this.closeCoWebsites();
|
||||
this.closeCoWebsites().catch((e) => console.error(e));
|
||||
});
|
||||
|
||||
const buttonFullScreenFrame = HtmlUtils.getElementByIdOrFail(cowebsiteFullScreenButtonId);
|
||||
|
@ -515,70 +515,72 @@ class CoWebsiteManager {
|
|||
throw new Error("Too many we");
|
||||
}
|
||||
|
||||
Promise.resolve(callback(this.cowebsiteBufferDom)).then((iframe) => {
|
||||
iframe?.classList.add("pixel");
|
||||
Promise.resolve(callback(this.cowebsiteBufferDom))
|
||||
.then((iframe) => {
|
||||
iframe?.classList.add("pixel");
|
||||
|
||||
if (!iframe.id) {
|
||||
do {
|
||||
iframe.id = "cowebsite-iframe-" + (Math.random() + 1).toString(36).substring(7);
|
||||
} while (this.getCoWebsiteById(iframe.id));
|
||||
}
|
||||
|
||||
const onloadPromise = new Promise<void>((resolve) => {
|
||||
iframe.onload = () => resolve();
|
||||
});
|
||||
|
||||
const icon = this.generateCoWebsiteIcon(iframe);
|
||||
|
||||
const coWebsite = {
|
||||
iframe,
|
||||
icon,
|
||||
position: position ?? this.coWebsites.length,
|
||||
};
|
||||
|
||||
// Iframe management on mobile
|
||||
icon.addEventListener("click", () => {
|
||||
if (this.isSmallScreen()) {
|
||||
this.moveRightPreviousCoWebsite(coWebsite, 0);
|
||||
if (!iframe.id) {
|
||||
do {
|
||||
iframe.id = "cowebsite-iframe-" + (Math.random() + 1).toString(36).substring(7);
|
||||
} while (this.getCoWebsiteById(iframe.id));
|
||||
}
|
||||
});
|
||||
|
||||
this.coWebsites.push(coWebsite);
|
||||
this.cowebsiteSubIconsDom.appendChild(icon);
|
||||
const onloadPromise = new Promise<void>((resolve) => {
|
||||
iframe.onload = () => resolve();
|
||||
});
|
||||
|
||||
const onTimeoutPromise = new Promise<void>((resolve) => {
|
||||
setTimeout(() => resolve(), 2000);
|
||||
});
|
||||
const icon = this.generateCoWebsiteIcon(iframe);
|
||||
|
||||
this.currentOperationPromise = this.currentOperationPromise
|
||||
.then(() => Promise.race([onloadPromise, onTimeoutPromise]))
|
||||
.then(() => {
|
||||
if (coWebsite.position === 0) {
|
||||
this.openMain();
|
||||
if (widthPercent) {
|
||||
this.widthPercent = widthPercent;
|
||||
}
|
||||
const coWebsite = {
|
||||
iframe,
|
||||
icon,
|
||||
position: position ?? this.coWebsites.length,
|
||||
};
|
||||
|
||||
setTimeout(() => {
|
||||
this.fire();
|
||||
// Iframe management on mobile
|
||||
icon.addEventListener("click", () => {
|
||||
if (this.isSmallScreen()) {
|
||||
this.moveRightPreviousCoWebsite(coWebsite, 0);
|
||||
}
|
||||
});
|
||||
|
||||
this.coWebsites.push(coWebsite);
|
||||
this.cowebsiteSubIconsDom.appendChild(icon);
|
||||
|
||||
const onTimeoutPromise = new Promise<void>((resolve) => {
|
||||
setTimeout(() => resolve(), 2000);
|
||||
});
|
||||
|
||||
this.currentOperationPromise = this.currentOperationPromise
|
||||
.then(() => Promise.race([onloadPromise, onTimeoutPromise]))
|
||||
.then(() => {
|
||||
if (coWebsite.position === 0) {
|
||||
this.openMain();
|
||||
if (widthPercent) {
|
||||
this.widthPercent = widthPercent;
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
this.fire();
|
||||
position !== undefined
|
||||
? this.moveRightPreviousCoWebsite(coWebsite, coWebsite.position)
|
||||
: this.moveCoWebsite(coWebsite, coWebsite.position);
|
||||
}, animationTime);
|
||||
} else {
|
||||
position !== undefined
|
||||
? this.moveRightPreviousCoWebsite(coWebsite, coWebsite.position)
|
||||
: this.moveCoWebsite(coWebsite, coWebsite.position);
|
||||
}, animationTime);
|
||||
} else {
|
||||
position !== undefined
|
||||
? this.moveRightPreviousCoWebsite(coWebsite, coWebsite.position)
|
||||
: this.moveCoWebsite(coWebsite, coWebsite.position);
|
||||
}
|
||||
}
|
||||
|
||||
return resolve(coWebsite);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Error loadCoWebsite => ", err);
|
||||
this.removeCoWebsiteFromStack(coWebsite);
|
||||
return reject();
|
||||
});
|
||||
});
|
||||
return resolve(coWebsite);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Error loadCoWebsite => ", err);
|
||||
this.removeCoWebsiteFromStack(coWebsite);
|
||||
return reject();
|
||||
});
|
||||
})
|
||||
.catch((e) => console.error("Error loadCoWebsite >=> ", e));
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -603,17 +605,21 @@ class CoWebsiteManager {
|
|||
return this.currentOperationPromise;
|
||||
}
|
||||
|
||||
public closeJitsi() {
|
||||
public async closeJitsi() {
|
||||
const jitsi = this.searchJitsi();
|
||||
if (jitsi) {
|
||||
this.closeCoWebsite(jitsi);
|
||||
return this.closeCoWebsite(jitsi);
|
||||
}
|
||||
}
|
||||
|
||||
public closeCoWebsites(): Promise<void> {
|
||||
this.currentOperationPromise = this.currentOperationPromise.then(() => {
|
||||
const promises: Promise<void>[] = [];
|
||||
this.coWebsites.forEach((coWebsite: CoWebsite) => {
|
||||
this.closeCoWebsite(coWebsite);
|
||||
promises.push(this.closeCoWebsite(coWebsite));
|
||||
});
|
||||
return Promise.all(promises).then(() => {
|
||||
return;
|
||||
});
|
||||
});
|
||||
return this.currentOperationPromise;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { JITSI_URL } from "../Enum/EnvironmentVariable";
|
||||
import { coWebsiteManager } from "./CoWebsiteManager";
|
||||
import { CoWebsite, coWebsiteManager } from "./CoWebsiteManager";
|
||||
import { requestedCameraState, requestedMicrophoneState } from "../Stores/MediaStore";
|
||||
import { get } from "svelte/store";
|
||||
|
||||
|
@ -140,8 +140,8 @@ class JitsiFactory {
|
|||
interfaceConfig?: object,
|
||||
jitsiUrl?: string,
|
||||
jitsiWidth?: number
|
||||
): void {
|
||||
coWebsiteManager.addCoWebsite(
|
||||
): Promise<CoWebsite> {
|
||||
return coWebsiteManager.addCoWebsite(
|
||||
async (cowebsiteDiv) => {
|
||||
// Jitsi meet external API maintains some data in local storage
|
||||
// which is sent via the appData URL parameter when joining a
|
||||
|
@ -200,7 +200,7 @@ class JitsiFactory {
|
|||
const jitsiCoWebsite = coWebsiteManager.searchJitsi();
|
||||
|
||||
if (jitsiCoWebsite) {
|
||||
coWebsiteManager.closeJitsi();
|
||||
coWebsiteManager.closeJitsi().catch((e) => console.error(e));
|
||||
}
|
||||
|
||||
this.jitsiApi.removeListener("audioMuteStatusChanged", this.audioCallback);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue