P2P Media LoaderTechnical Overview
Key components of the P2P network
All the components of the P2P network are free and open-source.
P2P Media Loader is an open-source JavaScript library that uses features of modern web browsers (HTML5 video and WebRTC) to deliver media over P2P and play it through integrations with popular HTML5 video players. It doesn't require any browser plugins or add-ons.
P2P Media Loader requires these browser features:
- WebRTC Data Channels to exchange data between peers
- Media Source Extensions or Managed Media Source, required by HLS.js, Shaka Player and other MSE-based engines for media playback
A STUN server is used by WebRTC to gather ICE candidates. There are many running public servers on the Public STUN server list.
A compatible WebTorrent tracker is used for WebRTC signaling and to create swarms of peers that download the same media stream. By default it uses public trackers: our own wss://tracker.novage.com.ua, wss://tracker.webtorrent.dev and wss://tracker.openwebtorrent.com. You can run your own tracker with open-source implementations: wt-tracker, Aquatic, OpenWebtorrent Tracker, bittorrent-tracker.
P2P Media Loader is configured to use public STUN and WebTorrent servers by default, so for simple use cases you don't need to run any server-side software. For production, we recommend running your own tracker.
How it works
A web browser runs a video player integrated with the P2P Media Loader library. Each instance of the library is called a peer, and many peers together form the P2P network.
P2P Media Loader first downloads media segments over HTTP(S) from the source server or CDN, so playback starts quickly. If no peers are available, it keeps downloading over HTTP(S), just like a traditional media stream.
It then sends media stream details and connection information (ICE candidates) to WebTorrent trackers, which return a list of other peers watching the same stream.
P2P Media Loader connects to these peers, downloads media segments from them, and shares the segments it already has.
Segments the swarm doesn't hold yet are downloaded over HTTP(S) and then distributed to others over P2P. Each such segment has one elected owner, chosen with rendezvous hashing applied to a P2P mesh: every peer scores itself and its connected neighbors for that segment — not the whole swarm — and the lowest score fetches it. The decision is local, so it needs no coordination round trip and works even though no peer sees the entire swarm. Ownership rotates from segment to segment, so no peer becomes the swarm's permanent origin, and if an owner is late, the others cover for it before playback is at risk.
A manifest-driven core
Since version 5.0, the core parses HLS and MPEG-DASH manifests itself. A player integration hands over every manifest the player fetches, routes segment requests through the core, and reports playback state. Segment identity comes from the manifest — the HLS media sequence number or the DASH presentation time — so peers on different players derive the same identity for the same segment and share one swarm. DASH SegmentBase streams share too: the core reads the segment index from the sidx box in the response the player already fetched.
How much traffic goes over P2P
In ideal conditions each segment is downloaded over HTTP(S) once and then shared between peers, so for N viewers of a live stream about 1/N of the traffic goes over HTTP(S) and the rest over P2P:
| Viewers of a live stream | HTTP(S) | P2P (ideal conditions) |
|---|---|---|
| 2 | 50% | 50% |
| 10 | 10% | 90% |
| 20 | 5% | 95% |
| 100 | 1% | 99% |
| 1,000 | 0.1% | 99.9% |
Version 5.0 brings live streams closer to this ideal. The rendezvous-hashing election stops peers from racing for their own copies of new segments, and placing the player deeper in the live window gives peers time to supply segments before the player asks.
For video on demand, the ratio depends on how many viewers watch the same part of the video at the same time. In real-world conditions it also depends on network conditions and peer connectivity.
Integrations and packages
- p2p-media-loader-core — the core, with HLS and MPEG-DASH manifest parsers
- p2p-media-loader-hlsjs — HLS.js integration
- p2p-media-loader-shaka — Shaka Player integration
- p2p-media-loader-dashjs — dash.js integration
- p2p-media-loader-videojs — Video.js 8 integration
Video.js 10 needs no separate package: it plays through HLS.js and dash.js, which the existing integrations drive. Players such as Vidstack, Clappr, MediaElement, Plyr, DPlayer, OpenPlayerJS and PlayerJS work through the integration for the engine they are built on.
All packages are available as ES modules on the jsDelivr CDN. The core comes in three builds — with both manifest parsers, HLS only, or DASH only — so a page carries only the parsers it uses. Every integration also ships an IIFE build for older browsers and Smart TVs.
DRM and encrypted streams
P2P Media Loader works with DRM-protected and encrypted streams, including Widevine, PlayReady, FairPlay and HLS AES-128:
- Peers exchange segments exactly as the CDN delivers them, still encrypted. Decryption stays in the video player; the library never decrypts media and never stores or shares decrypted data.
- Key and license requests are never intercepted and never travel between peers — they always go directly to your license server.
- Not applicable to per-session encryption or forensic watermarking, where every viewer receives different bytes for the same segment. P2P must be disabled for such content.
Web browsers support
- Chrome on desktops and Android
- Firefox on desktops and Android
- Safari on macOS
- Safari on iPadOS (iPad)
- Safari on iOS (iPhone, iOS 17.1+ required)
- Edge on Windows
It also runs inside native iOS and Android apps, including with native players.
Documentation
- Guides for HTML pages and web apps and for native mobile apps
- API documentation
- GitHub repository — source code, migration guide, changelog and FAQ
The engineering behind it
P2P Media Loader is built and maintained by Novage. Read the case study for how its architecture evolved over eight years, the key engineering decisions behind it, and what we're building next.