qhkr2z22o: Prefer direct mp4Url for feed video playback with hls fallback
This commit is contained in:
+17
-1
@@ -144,7 +144,7 @@ describe("video transcoding", () => {
|
||||
|
||||
it("keeps a just-published video as a thumbnail with no hlsUrl", () => {
|
||||
const [p] = vid(null);
|
||||
expect(p.media).toEqual([{ kind: "video", src: "https://i/t.jpg", hlsUrl: null }]);
|
||||
expect(p.media).toEqual([{ kind: "video", src: "https://i/t.jpg", hlsUrl: null, mp4Url: null }]);
|
||||
});
|
||||
|
||||
it("keeps a video with neither thumbnail nor hlsUrl as a pending card", () => {
|
||||
@@ -161,6 +161,22 @@ describe("video transcoding", () => {
|
||||
expect(upgradeVideos(shown, vid(null))).toBe(shown);
|
||||
});
|
||||
|
||||
it("captures mp4Url on the feed CDN and rejects other hosts", () => {
|
||||
const mk = (u: unknown) =>
|
||||
toCardPosts([post("9", "2026-10-19T10:00:00Z", { mediaItems: [{ mediaType: "video", thumbnailUrl: "https://i/t.jpg", mp4Url: u }] })])[0].media[0];
|
||||
expect(mk("https://cdn.feed.sharedservices.vt.com/v.mp4").mp4Url).toBe("https://cdn.feed.sharedservices.vt.com/v.mp4");
|
||||
expect(mk("https://evil.example/v.mp4").mp4Url).toBeNull();
|
||||
expect(mk("http://cdn.feed.sharedservices.vt.com/v.mp4").mp4Url).toBeNull();
|
||||
});
|
||||
|
||||
it("upgrades the thumbnail in place when only mp4Url appears", () => {
|
||||
const withMp4 = toCardPosts([post("7", "2026-10-19T10:00:00Z", { mediaItems: [{ mediaType: "video", thumbnailUrl: "https://i/t.jpg", mp4Url: "https://cdn.feed.sharedservices.vt.com/v.mp4" }] })]);
|
||||
const shown = vid(null);
|
||||
const next = upgradeVideos(shown, withMp4);
|
||||
expect(next[0].media[0].mp4Url).toContain("cdn.feed");
|
||||
expect(upgradeVideos(next, vid(null))).toBe(next);
|
||||
});
|
||||
|
||||
it("renders the thumbnail while transcoding and the player once hlsUrl is present", () => {
|
||||
const html = render({ posts: vid(null) });
|
||||
expect(html).toContain("https://i/t.jpg");
|
||||
|
||||
@@ -5,6 +5,7 @@ import { PostCard } from "@/components/PostCard";
|
||||
import { toCardPosts } from "@/lib/feed-model";
|
||||
import { choosePlayback, supportsNativeHls } from "@/lib/video-playback";
|
||||
|
||||
const MP4 = "https://cdn.feed.sharedservices.vt.com/v.mp4";
|
||||
const HLS = "https://stream.mux.com/abc.m3u8";
|
||||
const item = (media: Record<string, unknown>) => ({
|
||||
type: "post",
|
||||
@@ -55,4 +56,24 @@ describe("video media in the card", () => {
|
||||
expect(out).not.toContain("<video");
|
||||
expect(out).toContain('src="https://i/v.jpg"');
|
||||
});
|
||||
it("prefers mp4Url: plain video source, no hls.js needed", () => {
|
||||
const out = html({ ...video, hlsUrl: HLS, mp4Url: MP4 });
|
||||
expect(out).toContain("<video");
|
||||
expect(out).toContain(`src="${MP4}"`);
|
||||
expect(out).toContain('poster="https://i/v.jpg"');
|
||||
expect(out).not.toContain("m3u8");
|
||||
expect(out).not.toContain("autoplay");
|
||||
});
|
||||
it("mp4Url alone renders the player", () => {
|
||||
expect(html({ ...video, mp4Url: MP4 })).toContain(`src="${MP4}"`);
|
||||
});
|
||||
it("hls-only video renders a video without a src (hls.js attaches it)", () => {
|
||||
const out = html({ ...video, hlsUrl: HLS });
|
||||
expect(out).toContain("<video");
|
||||
expect(out).not.toContain(`src="${HLS}"`);
|
||||
});
|
||||
it("rejects an mp4Url off the feed CDN", () => {
|
||||
const out = html({ ...video, mp4Url: "https://evil.example/v.mp4" });
|
||||
expect(out).not.toContain("<video");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user