broadcast-hls is a professional HTTP Live Streaming (HLS
.m3u8) and IPTV (.m3u) web platform engineered for live stream playback, real-time telemetry analytics, multi-stream monitoring, IPTV playlist management, channel zapping, and zero-copy CORS/Mixed-Content proxying.
- Application Purpose
- Audit & Architectural Improvements
- 1. Media Engine Resilience & Auto-Recovery
- 2. High-Throughput Zero-Copy Stream Proxy
- 3. IPTV Playlist Engine & Default Auto-Seeding
- 4. Player Controls & Settings Popover Redesign
- 5. Component Modularization & Sub-Directories
- 6. Mobile-First Responsive Design
- 7. Framework Alignment & CSS Architecture
- Understanding HLS & IPTV Playlists
- Why Proxy HLS? (CORS & Mixed Content)
- Key Features
- Project Architecture
- API Endpoints
- Quick Start & Local Setup
- Keyboard Shortcuts
- License
Testing, monitoring, and playing live HLS streams over the open web introduces technical challenges:
- CORS Restrictions: Many IPTV, sports, and live broadcast streams block browser playback due to missing Cross-Origin Resource Sharing (
Access-Control-Allow-Origin) response headers. - Mixed Content Blocking: Web Browsers block unencrypted
http://streams when hosted on securehttps://origins. - Lack of Diagnostics: Default HTML5 video elements do not expose real-time metrics such as buffer length, latency to live edge, dropped frames, or active ABR variant bitrates.
- IPTV Playlist Parsing: Public and commercial IPTV playlists (
.m3u) contain thousands of channels with logos, categories, and custom HTTP headers (#EXTVLCOPT:http-user-agent). - Multi-View Requirements: Broadcast engineers and sports operators often need to monitor multiple live feeds simultaneously in a synchronized layout.
broadcast-hls resolves these challenges in a unified web application styled after modern broadcast software and developer dashboards.
Following an in-depth codebase audit and refactoring process, the following technical enhancements were implemented across the architecture:
- 2-Stage Media Error Handling: Implemented multi-tier media error recovery inside
hooks/useHlsPlayer.ts. On first media error, the engine executesrecoverMediaError(). On second consecutive failure, it callsswapAudioCodec()to switch audio demuxers before retrying media decoding. - Exponential Backoff Reconnecting: Added retry attempt tracking with exponential delays (
1s,2s,4s,8s,16s) for non-fatal network interruptions before raising a fatal offline error state. - Memory Leak Protection: Enhanced component unmount logic by detaching media (
hls.detachMedia()), stopping segment loading (hls.stopLoad()), destroying instances (hls.destroy()), and resetting video source attributes (video.removeAttribute('src'); video.load()).
- Zero-Copy Streaming: Refactored
/api/stream/proxyto pipe binary media chunks (.ts,.m4s,.mp4,.aac) directly using WebReadableStreaminstead of buffering payloads into server RAM viaArrayBufferor inspecting text, resolving Nodefetchstream locking 500 Internal Server Errors. - Custom Header Passthrough: Added support for
ua(User-Agent) andreferersearch parameters to forward custom headers required by strict IPTV servers. - Proxy Unwrapping Helper: Added
cleanStreamUrlto unwrap nested proxy paths and extract clean target stream URLs.
- Default 12,000+ All Channels Index: Updated default IPTV channel guide auto-seed to the main All Channels Index (
index.m3u). - M3U Metadata Parser (
utils/m3uParser.ts): Parses#EXTINFmetadata (tvg-logo,group-title,tvg-country,tvg-language) and#EXTVLCOPTcustom headers. - Local Storage State Store (
hooks/useIptvStore.ts): Saves imported playlists, active selection, and starred favorite channels (β) across browser sessions. - Disk File Upload: Direct
.m3uand.m3u8file disk parsing.
- Top-Left Video Overlay LIVE Badge: Relocated the LIVE sync indicator (
[π΄ LIVE]) to a sleek top-left video stage overlay alongside the channel title, freeing up bottom control bar real estate. - Hierarchical Settings Menu: Created a macOS/iOS style flyout menu (
components/player/menu/) with submenus for Quality (QualityMenu.tsx), Audio Tracks (AudioMenu.tsx), Subtitles (SubtitleMenu.tsx), Playback Speed (SpeedMenu.tsx), and Low Latency mode. - Auto-Hide Freeze State: Automatically freezes the 2.5s auto-hide timer whenever Settings or diagnostic modals are open.
- TV Zapping Pill: Added explicit
ChannelZapButtons.tsxcomponent with channel counter and hotkeys (N/P).
- Clean Component Separation: Extracted component sub-domains:
components/common/:StreamInput.tsx,StreamUrlForm.tsx,StreamSamplePresets.tsx,StreamValidationBadge.tsx,ProxyToggle.tsx,Footer.tsx.components/iptv/:IptvPresetGrid.tsx,IptvImportBar.tsx,IptvViewControls.tsx,IptvCategoryPills.tsx,IptvChannelCard.tsx.components/player/menu/:QualityMenu.tsx,AudioMenu.tsx,SubtitleMenu.tsx,SpeedMenu.tsx.hooks/: Extracted state & event handlers intouseMainApp.ts,useHlsPlayer.ts,useIptvStore.ts,useKeyboardShortcuts.ts, anduseStreamHistory.ts.
- Responsive Navigation Header: Designed a collapsible mobile navigation drawer with touch-optimized buttons and hamburger toggle (
Menu/X). - Touch Gesture Overlay: Large centered play/pause and Β±10s seek buttons overlayed on video stage for mobile tap interaction.
- Next.js Font Optimization: Configured Google Fonts (
InterandJetBrains Mono) usingnext/font/googleinapp/layout.tsxfor zero Cumulative Layout Shift (CLS). - Tailwind CSS Directive Ordering: Cleaned
app/globals.cssto begin directly with@tailwind base; @tailwind components; @tailwind utilities;in accordance with Next.js framework setup guides.
Developed by Apple Inc. in 2009 (IETF RFC 8216), HTTP Live Streaming (HLS) is an HTTP-based adaptive bitrate streaming protocol. It splits video content into small media segments (.ts, .m4s, or .aac) and delivers them over standard HTTP web servers.
An IPTV M3U Playlist is a text file listing channels, logos, categories, and stream URIs:
#EXTM3U
#EXTINF:-1 tvg-id="ESPN.us" tvg-logo="https://..." group-title="Sports", ESPN HD
http://example.com/live/espn.m3u8The application includes 8 pre-configured global IPTV playlist presets:
- All Channels (12,000+ Default Index):
https://iptv-org.github.io/iptv/index.m3u - Grouped by Category:
https://iptv-org.github.io/iptv/index.category.m3u - News Channels (930+):
https://iptv-org.github.io/iptv/categories/news.m3u - Sports Channels (320+):
https://iptv-org.github.io/iptv/categories/sports.m3u - Movies & Cinema (350+):
https://iptv-org.github.io/iptv/categories/movies.m3u - Music & Hits (650+):
https://iptv-org.github.io/iptv/categories/music.m3u - Grouped by Country:
https://iptv-org.github.io/iptv/index.country.m3u - Grouped by Language:
https://iptv-org.github.io/iptv/index.language.m3u
Loading a remote .m3u8 link from a third-party server directly in a client browser can trigger:
- CORS Errors: Browsers reject cross-origin requests if the remote server omits
Access-Control-Allow-Origin: *. - Mixed Content Errors: Attempting to load
http://stream.m3u8from anhttps://origin triggers security blocks.
The serverless proxy route (/api/stream/proxy):
- Requests the remote
.m3u8playlist server-side. - Rewrites relative segment URIs into fully-qualified proxied endpoints.
- Streams segment byte data back to the browser with explicit
Access-Control-Allow-Origin: *headers and zero-copy streaming.
- Hero Video Player: Built on
hls.jswith top-left overlay LIVE badge, space-saving controls, and auto-hide freeze state. - IPTV Playlist Manager: Full IPTV tab with LocalStorage persistence, disk upload, and search across 12,000+ streams.
- TV Zapping: Next/Previous channel flipping via control bar buttons or keyboard shortcuts (
N/P). - Starred Favorites: Star favorite channels (β) for instant access across sessions.
- 4K UHD & Multi-Quality Selector: Supports adaptive Auto mode or forced quality levels (4K 2160p, 1440p, 1080p, 720p).
- 10s Seek Controls & Live Edge Sync: Quick -10s and +10s seek buttons alongside top-left LIVE edge synchronization.
- Multi-Audio Track & WebVTT Subtitles: Switch multi-language audio tracks and toggle closed captions.
- CORS & HTTP Proxy Engine: Toggleable zero-copy proxying for seamless playback of restricted or HTTP streams.
- Real-time Telemetry & Health Panel: Live monitoring of buffer length, latency to live edge, FPS, dropped frames, and download speed.
- Multi-Stream Grid: View up to 4 concurrent live streams in a 2x2 multi-view layout with independent volume and fullscreen controls.
- Stream History: Persists recent stream URLs in browser
localStorage. - Shareable Direct Links: Share links pre-configured with query parameters (
/?url=...&proxy=true). - Mobile & Touch Optimization: Responsive layouts tailored for smartphones, tablets, and desktop displays.
broadcast-hls/
βββ app/
β βββ api/stream/
β β βββ proxy/route.ts # Serverless zero-copy CORS & HTTP proxy
β β βββ validate/route.ts # Stream manifest & header validator
β β βββ health/route.ts # Latency & ping health probe
β β βββ history/route.ts # Server-side history endpoint
β βββ globals.css # CSS design system tokens & utilities
β βββ layout.tsx # Root layout, next/font optimization & meta tags
β βββ page.tsx # Main app container & tab router
βββ components/
β βββ common/
β β βββ Footer.tsx # Application footer component
β β βββ ProxyToggle.tsx # CORS Proxy toggle switch
β β βββ StreamInput.tsx # Stream URL input bar
β β βββ StreamSamplePresets.tsx # Quick stream sample preset chips
β β βββ StreamUrlForm.tsx # Main URL form input
β β βββ StreamValidationBadge.tsx # Stream validation status badge
β βββ iptv/
β β βββ IptvCategoryPills.tsx # Category filter pills
β β βββ IptvChannelCard.tsx # Channel card item
β β βββ IptvImportBar.tsx # Playlist import & file upload bar
β β βββ IptvPresetGrid.tsx # Preset playlist cards
β β βββ IptvViewControls.tsx # Search & grid/list layout controls
β βββ player/
β β βββ menu/
β β β βββ AudioMenu.tsx # Multi-audio track selector
β β β βββ QualityMenu.tsx # 4K UHD / HD video quality menu
β β β βββ SpeedMenu.tsx # Playback speed menu
β β β βββ SubtitleMenu.tsx # Closed caption subtitles menu
β β βββ ChannelZapButtons.tsx # TV Zapping channel buttons
β β βββ KeyboardShortcutsModal.tsx# Hotkeys documentation modal
β β βββ PlayerControls.tsx # Bottom playback control bar
β β βββ PlayerOverlayMessages.tsx # Error & loading status overlay
β β βββ PlayerSkeleton.tsx # Video player skeleton loader
β β βββ ProgressBar.tsx # Timeline buffer progress bar
β β βββ SettingsMenu.tsx # Hierarchical settings popover
β β βββ StreamInfoModal.tsx # Diagnostic telemetry modal
β β βββ VideoPlayer.tsx # Core video player & stage overlay
β β βββ VolumeControl.tsx # Mute & volume slider
β βββ telemetry/
β β βββ StreamHealthPanel.tsx # Diagnostic health panel & metrics
β βββ IptvChannelGuide.tsx # Responsive IPTV channel drawer
β βββ IptvPlaylistTab.tsx # Full IPTV channel guide tab
β βββ MultiView.tsx # 2x2 multi-stream grid player
β βββ Navbar.tsx # Responsive navigation header
β βββ RecentStreams.tsx # Stream history list
βββ hooks/
β βββ useHlsPlayer.ts # hls.js lifecycle & auto-recovery hook
β βββ useIptvStore.ts # LocalStorage IPTV store (Default: index.m3u)
β βββ useKeyboardShortcuts.ts # Keyboard shortcuts listener
β βββ useMainApp.ts # Main page state container hook
β βββ useStreamHistory.ts # LocalStorage stream history hook
βββ utils/
β βββ m3uParser.ts # M3U IPTV parser & URL unwrapper utility
βββ types/
β βββ stream.ts # TypeScript interfaces
βββ package.json
βββ README.md
GET /api/stream/proxy?url=<ENCODED_M3U8_URL>&ua=<USER_AGENT>&referer=<REFERER>
- Fetches target
.m3u8manifest or segment byte data. - Forwards optional custom
User-AgentandRefererheaders. - Rewrites internal segment URIs to route through the proxy.
- Returns payload with
Access-Control-Allow-Origin: *and zero-copy streaming.
POST /api/stream/validate
- Body:
{ "url": "https://example.com/stream.m3u8" } - Response: Returns stream validity, content-type (
application/x-mpegURL), resolution, and codecs.
- Node.js 18.x or higher
- npm or pnpm
git clone https://github.com/Muhammed-Rizin/broadcast-hls.git
cd broadcast-hls
npm installnpm run devOpen http://localhost:3000 in your web browser.
# Run ESLint check
npm run lint
# Compile Next.js production build
npm run build
# Start production server
npm run start| Shortcut | Action |
|---|---|
Space / K |
Toggle Play / Pause |
F |
Toggle Fullscreen |
M |
Toggle Mute |
J / β |
Seek 10 seconds backward |
L / β |
Seek 10 seconds forward |
N / PageDown |
Next IPTV Channel |
P / PageUp |
Previous IPTV Channel |
0 |
Jump to Live edge |
Distributed under the MIT License. See LICENSE for details.