Skip to content

feat(ui, llc): play HLS livestreams on the web with hls.js - #1794

Draft
renefloor wants to merge 4 commits into
feat/hls-ios-playerfrom
feat/hls-web-player
Draft

renefloor wants to merge 4 commits into
feat/hls-ios-playerfrom
feat/hls-web-player

Conversation

@renefloor

Copy link
Copy Markdown
Contributor

🎯 Goal

Step 6 of HLS_PLAN.md (FLU-1266): the web HLS player of stream_video_hls. Stacked on #1793.

🛠 Implementation details

  • WebHlsPlayer (Dart, package:web + dart:js_interop):
    • plays the playlist in a hidden 1 px <video playsinline>;
    • uses hls.js where Media Source Extensions (or Safari's Managed Media Source) exist, and native HLS otherwise;
    • copies frames with requestVideoFrameCallback and ui_web.createImageFromTextureSource, so the video is drawn inside Flutter (RawImage) as on mobile and overlays work without a platform view.
  • hls.js 1.6.19 (Apache-2.0) is vendored like the video filters in feat(repo, samples): video filters on web #1744:
    • tool/web_bundle pins it with npm and builds its ES module with esbuild into web_files/hls.min.js, a web-only asset;
    • melos run update:web_hls [-- <version>] rebuilds it, and a test checks that web_files matches the pin;
    • the player imports it with import() on its first start, so it needs no global and no index.html change.
  • Config, retries and errors follow the JS SDK's HLSPlayer:
    • loads retry with a 1–5 s backoff, and a permanent 4xx on a playlist fails at once;
    • liveSyncDurationCount 3, liveMaxLatencyDurationCount 6, initialLiveManifestSize 1;
    • capLevelToPlayerSize is off because the element is 1 px.
  • Every failure reaches the call: a failed start, hls.js not loading, a throw in an hls.js callback, frame copies that keep failing, and native <video> errors.
  • Autoplay:
    • a refused play reports paused and the new HlsPlayerAutoplayBlocked event;
    • the call registers its HLS playback as a blocked source in RemoteAudioPlayback, so CallState.isWebAudioPlaybackBlocked turns true;
    • PlatformAudioController.resumeWebAudioPlayback() from a gesture starts playback;
    • the load timeout pauses while blocked.
  • Audio output:
    • the contract gains setAudioOutput, and the call follows CallState.audioOutputDevice;
    • the web player uses setSinkId; the native players follow the system route;
    • Call.setAudioOutputDevice now works on an HLS call, which has no SFU session.
  • Metrics: fragment bytes and duration, getVideoPlaybackQuality(), the buffered and seekable ranges, and hls.playingDate.
  • The example app gains a web target.

🧪 Testing

  • In Chrome (the app's built-in browser), with a release build playing a public HLS stream:
    • frames are drawn in Flutter;
    • events arrive as loading → playing → firstFrame;
    • metrics are filled in;
    • pause, then resume, seeks back to the live position;
    • hls.js loads as a module (window.Hls stays undefined).
  • flutter test passes in stream_video (autoplay, load timer, audio output, setSourceBlocked) and in stream_video_hls.
  • Not checked yet: Safari/Managed Media Source, the native fallback with CORS, and a Stream HLS livestream (dogfooding, step 10).

🤖 Generated with Claude Code

renefloor and others added 3 commits December 4, 2026 17:42
`StreamHlsPlayerFactory` now supports the web. `WebHlsPlayer` plays the
playlist in a hidden `<video>` with hls.js where Media Source Extensions
exist, else natively, and copies its frames into images the renderer
paints, so the video is drawn inside Flutter like on mobile. hls.js 1.6.19
ships as a web-only asset, injected on the first playback, and is rebuilt
by `melos run update:web_hls`. The config, retries and error handling follow
the JS SDK's player.

A play the browser's autoplay policy refuses is reported as
`HlsPlayerAutoplayBlocked`; the call then counts its HLS playback as blocked
web audio, so `CallState.isWebAudioPlaybackBlocked` turns true and
`resumeWebAudioPlayback()` from a gesture starts it. The player contract
gains `setAudioOutput`, which the call drives from its audio output device
and the web player applies with `setSinkId`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Import hls.js as an ES module built by esbuild, so the player needs no
  `window.Hls` and a page's AMD loader cannot capture it; the bundle drops
  the source-map comment it shipped without its map. A test checks that
  `web_files` holds the pinned version.
- Fail playback when `start` throws, when hls.js does not load (instead of
  reporting the browser as unsupported), when an hls.js callback throws and
  when frame copies keep failing; report hls.js's non-fatal internal errors
  as recoverable, and map native `<video>` errors to their reasons.
- Let a refused `setSinkId` reach the call.
- Start the load timer again once a gesture resumes a blocked player, and
  clear the blocked state on a broadcast restart.
- Record the audio output chosen on an HLS call, which has no SFU session,
  so the web player follows it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the v2 label Dec 4, 2026
@getstream-metis

Copy link
Copy Markdown

👋 Hi Rene, still cooking? 🍳

I'm Jeffery, Stream's review agent. I look for bugs, regressions, missing tests and slow paths, and I only post findings I've checked against the code.

📝 This PR is a draft, so I'll keep my hands off for now. Mark it Ready for review and a ✅ box to start my review shows up right here.

Can't wait? Comment /jeffery review now and I'll start the moment it's ready. I'll stay quiet unless you ask.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant