Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[space][web] Fall back when video frame callbacks are unavailable

Anand Baburajan9a9f3945fb3a
diff --git a/web/apps/space/src/components/PostVideoContent.ts b/web/apps/space/src/components/PostVideoContent.ts
index 8ef043dd81..33045d5ad2 100644
--- a/web/apps/space/src/components/PostVideoContent.ts
+++ b/web/apps/space/src/components/PostVideoContent.ts
@@ -217,8 +217,8 @@ export const createSpaceVideoContent = (
button.disabled = false;
button.setAttribute("aria-hidden", "true");
video.setAttribute("aria-label", "Pause video");
- if (cover && cover.style.opacity != "0" && coverFrame == undefined)
- coverFrame = video.requestVideoFrameCallback(() => {
+ if (cover && cover.style.opacity != "0" && coverFrame == undefined) {
+ const reveal = () => {
coverFrame = undefined;
cover.style.transition = window.matchMedia(
"(prefers-reduced-motion: reduce)",
@@ -226,7 +226,11 @@ export const createSpaceVideoContent = (
? "none"
: "opacity 150ms ease-out";
cover.style.opacity = "0";
- });
+ };
+ if (typeof video.requestVideoFrameCallback == "function")
+ coverFrame = video.requestVideoFrameCallback(reveal);
+ else reveal();
+ }
};
const pause = () => {
generation++;
diff --git a/web/apps/space/tests/post-video-content.test.ts b/web/apps/space/tests/post-video-content.test.ts
index 83b65309bc..b852c0892e 100644
--- a/web/apps/space/tests/post-video-content.test.ts
+++ b/web/apps/space/tests/post-video-content.test.ts
@@ -212,6 +212,29 @@ test("a preloaded viewer video dissolves its cover only after playback presents
expect(load).not.toHaveBeenCalled();
});
+test("viewer playback dissolves its cover without video-frame callback APIs", async () => {
+ const content = create(false);
+ Reflect.deleteProperty(content.video, "requestVideoFrameCallback");
+ Reflect.deleteProperty(content.video, "cancelVideoFrameCallback");
+ await content.preload();
+ content.video.onloadeddata?.();
+ expect(content.cover?.style.opacity).toBe("1");
+ content.play();
+ await vi.advanceTimersByTimeAsync(0);
+ expect(content.video.paused).toBe(false);
+ expect(content.video.getAttribute("src")).toBe("blob:video");
+ expect(content.error.hidden).toBe(true);
+ expect(content.cover?.style.opacity).toBe("0");
+ expect(content.cover?.style.transition).toBe("opacity 150ms ease-out");
+ content.pause();
+ expect(content.video.paused).toBe(true);
+ content.play(true);
+ await vi.advanceTimersByTimeAsync(0);
+ expect(content.video.paused).toBe(false);
+ expect(content.error.hidden).toBe(true);
+ expect(load).toHaveBeenCalledOnce();
+});
+
test("viewer playback loads during the opening animation and waits for it to land", async () => {
const opening = Promise.withResolvers<undefined>();
const content = create(false, "blob:poster", {