// Chooses how a feed video plays. Pure, so it is unit-testable without a browser. export type Playback = "none" | "native" | "hlsjs"; export interface PlaybackEnv { /** True when the browser can play .m3u8 directly (Safari). */ nativeHls: boolean; /** True when hls.js (Media Source Extensions) is supported. */ hlsJsSupported: boolean; } /** * No hlsUrl: thumbnail only. hls.js (Media Source Extensions) is preferred * because Chromium reports partial native HLS support it cannot honour; native * HLS is only chosen where hls.js is unsupported (Safari on iOS). */ export function choosePlayback(hlsUrl: string | null | undefined, env: PlaybackEnv): Playback { if (!hlsUrl) return "none"; if (env.hlsJsSupported) return "hlsjs"; return env.nativeHls ? "native" : "none"; } export function supportsNativeHls(video: Pick): boolean { return video.canPlayType("application/vnd.apple.mpegurl") !== ""; }