Skip to content

Repository files navigation

HLS Service Worker

Service Worker for HLS video prefetching

Architecture

arch preview

Build

node build.js   # Concatenates src/ → sw.js

Demo

uv run python3 web.py
# Chrome: http://localhost:3001/webtest/

vod example preview

Test

node test_offline_startup.js

Key Features

  • Progressive playlist parsing - Start playback before full manifest loads
  • Lookahead prefetch - Preload segments ahead of playback position
  • Multi-tier cache - Memory → Disk (Cache API) with quota enforcement
  • Stall detection + range requests - Switch to parallel range fetches on slow downloads
  • Recovery/cooldown - Retry with backoff, host/segment cooldown

Messages (Client → SW)

Type Purpose
LINE_CHANGE Reset state, send INITIAL to client
PREPARE_START Parse manifest, prefetch target + lookahead
TIMELINE_JUMP Set seek target time
PLAYER_STATE isPaused, seeked
PLAYBACK_POSITION_UPDATE Periodic position for adaptive prefetch

Messages (SW → Client)

Type Purpose
INITIAL Client should re-initialize
PREPARE_PROGRESS Preparation progress %
PREPARE_START_READY Target segment ready

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages