p2p-media-loader-dashjs 5.0.0-alpha.2 → 5.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -27,6 +27,7 @@ This library makes it possible to build large-scale P2P mesh networks — often
27
27
 
28
28
  ## Related Software
29
29
 
30
+ - [wt-tracker-rust](https://github.com/Novage/wt-tracker-rust) (recommended): a multi-core WebTorrent tracker in Rust, a port of wt-tracker that runs `wss://tracker.novage.com.ua`. A 2-core Oracle Cloud **Free** Tier Ampere A1 instance can serve more than 200k peers, about 120k on average within the free monthly traffic (one WebSocket connection per peer).
30
31
  - [wt-tracker](https://github.com/Novage/wt-tracker): a high-performance WebTorrent tracker for Node.js using [µWebSockets.js](https://github.com/uNetworking/uWebSockets.js).
31
32
  - [Aquatic](https://github.com/greatest-ape/aquatic): a high-performance WebTorrent and BitTorrent tracker written in Rust.
32
33
  - [bittorrent-tracker](https://github.com/webtorrent/bittorrent-tracker): official WebTorrent tracker implementation for Node.js.
@@ -35,7 +36,8 @@ This library makes it possible to build large-scale P2P mesh networks — often
35
36
 
36
37
  - Guides [for HTML pages and web apps](https://novage.com.ua/blog/setting-up-p2p-video-on-a-web-page-in-5-minutes-for-free) and [for native mobile apps](https://novage.com.ua/blog/integrate-p2p-video-streaming-into-mobile-application)
37
38
  - [API documentation](https://novage.github.io/p2p-media-loader/docs/v5.0/)
38
- - [v3 → v4 migration guide](https://github.com/Novage/p2p-media-loader/blob/main/MIGRATION.md)
39
+ - [v4 → v5 migration guide](https://github.com/Novage/p2p-media-loader/blob/main/MIGRATION.md)
40
+ - [Changelog](https://github.com/Novage/p2p-media-loader/blob/main/CHANGELOG.md)
39
41
  - [P2P development, support & consulting](https://novage.com.ua/)
40
42
  - [Demo](http://novage.com.ua/p2p-media-loader/demo.html)
41
43
  - [Contributing to our project](https://github.com/Novage/p2p-media-loader/blob/main/CONTRIBUTING.md)
@@ -44,27 +46,27 @@ This library makes it possible to build large-scale P2P mesh networks — often
44
46
  - [Technical overview](http://novage.com.ua/p2p-media-loader/technical-overview.html)
45
47
  - npm packages
46
48
  - [Core](https://npmjs.com/package/p2p-media-loader-core)
47
- - [Hls.js integration](https://npmjs.com/package/p2p-media-loader-hlsjs)
49
+ - [HLS.js integration](https://npmjs.com/package/p2p-media-loader-hlsjs)
48
50
  - [Shaka Player integration](https://npmjs.com/package/p2p-media-loader-shaka)
49
51
  - [dash.js integration](https://npmjs.com/package/p2p-media-loader-dashjs)
50
- - [video.js 8 integration](https://npmjs.com/package/p2p-media-loader-videojs)
52
+ - [Video.js 8 integration](https://npmjs.com/package/p2p-media-loader-videojs)
51
53
  - ES modules CDN
52
54
  - [Core](https://cdn.jsdelivr.net/npm/p2p-media-loader-core@^5/dist/) — three builds: `p2p-media-loader-core.es.min.js` with the HLS and MPEG-DASH manifest parsers, `p2p-media-loader-core-hls.es.min.js` and `p2p-media-loader-core-dash.es.min.js` with one. Load exactly one; each carries its own copy of the core
53
- - [Hls.js integration](https://cdn.jsdelivr.net/npm/p2p-media-loader-hlsjs@^5/dist/)
55
+ - [HLS.js integration](https://cdn.jsdelivr.net/npm/p2p-media-loader-hlsjs@^5/dist/)
54
56
  - [Shaka Player integration](https://cdn.jsdelivr.net/npm/p2p-media-loader-shaka@^5/dist/)
55
57
  - [dash.js integration](https://cdn.jsdelivr.net/npm/p2p-media-loader-dashjs@^5/dist/)
56
- - [video.js 8 integration](https://cdn.jsdelivr.net/npm/p2p-media-loader-videojs@^5/dist/)
58
+ - [Video.js 8 integration](https://cdn.jsdelivr.net/npm/p2p-media-loader-videojs@^5/dist/)
57
59
  - IIFE builds CDN (for older browsers and Smart TVs)
58
- - [Hls.js integration](https://cdn.jsdelivr.net/npm/p2p-media-loader-hlsjs@^5/dist/p2p-media-loader-hlsjs.iife.min.js)
60
+ - [HLS.js integration](https://cdn.jsdelivr.net/npm/p2p-media-loader-hlsjs@^5/dist/p2p-media-loader-hlsjs.iife.min.js)
59
61
  - [Shaka Player integration](https://cdn.jsdelivr.net/npm/p2p-media-loader-shaka@^5/dist/p2p-media-loader-shaka.iife.min.js)
60
62
  - [dash.js integration](https://cdn.jsdelivr.net/npm/p2p-media-loader-dashjs@^5/dist/p2p-media-loader-dashjs.iife.min.js)
61
- - [video.js 8 integration](https://cdn.jsdelivr.net/npm/p2p-media-loader-videojs@^5/dist/p2p-media-loader-videojs.iife.min.js)
63
+ - [Video.js 8 integration](https://cdn.jsdelivr.net/npm/p2p-media-loader-videojs@^5/dist/p2p-media-loader-videojs.iife.min.js)
62
64
 
63
65
  ## Web Browsers Support
64
66
 
65
67
  - **Chrome** on desktops and Android
66
68
  - **Firefox** on desktops and Android
67
- - **Sarafi** on macOS
69
+ - **Safari** on macOS
68
70
  - **Safari** on iPadOS (iPad)
69
71
  - **Safari** on iOS (iPhone, iOS version 17.1+ required)
70
72
  - **Edge** on Windows
@@ -73,18 +75,81 @@ This library makes it possible to build large-scale P2P mesh networks — often
73
75
 
74
76
  - Supports live and VOD streams over HLS or MPEG-DASH protocols
75
77
  - Supports multiple HTML5 video players and engines:
76
- - Engines: Hls.js, Shaka Player, dash.js, video.js 8 (VHS)
77
- - video.js 10 needs no integration package of ours: it plays HLS and MPEG-DASH through media adapters powered by Hls.js and dash.js, which the Hls.js and dash.js integrations drive directly
78
- - Video players: [Vidstack](https://www.vidstack.io/), [Clappr](http://clappr.io/), [MediaElement](https://www.mediaelementjs.com/), [Plyr](https://plyr.io/), [DPlayer](https://dplayer.diygod.dev/), [OpenPlayerJS](https://www.openplayerjs.com/), [PlayerJS](https://playerjs.com/) , and others that support Hls.js or Shaka video engines. These players can be integrated via custom integration with the library API.
78
+ - Engines: HLS.js, Shaka Player, dash.js, Video.js 8 (VHS)
79
+ - Video.js 10 needs no integration package of ours: it plays HLS and MPEG-DASH through media adapters powered by HLS.js and dash.js, which the HLS.js and dash.js integrations drive directly
80
+ - Video players: [Clappr](http://clappr.io/), [MediaElement](https://www.mediaelementjs.com/), [DPlayer](https://dplayer.diygod.dev/), [OpenPlayerJS](https://www.openplayerjs.com/), [PlayerJS](https://playerjs.com/) , and others that support HLS.js or Shaka video engines. These players can be integrated via custom integration with the library API.
81
+ - Make sure the player plays HLS through HLS.js, not through the browser's own HLS playback, which bypasses P2P. Safari and recent Chrome both report native HLS support, and some players prefer it by default: MediaElement, for one, needs `renderers: ["native_hls", "html5"]` to use HLS.js first.
79
82
  - Supports adaptive bitrate streaming of HLS and MPEG-DASH protocols
80
83
  - Supports DRM-protected and encrypted streams, including Widevine, PlayReady, FairPlay, and HLS AES-128:
81
84
  - 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
82
85
  - Key and license requests are never intercepted and never travel between peers — they always go directly to your license server
83
86
  - 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
84
87
  - There is no need for server-side software for simple use cases. By default **P2P Media Loader** uses publicly available servers:
85
- - WebTorrent trackers - [wss://tracker.webtorrent.dev](https://webtorrent.dev/), [wss://tracker.openwebtorrent.com](https://openwebtorrent.com/)
88
+ - WebTorrent trackers - [wss://tracker.novage.com.ua](https://novage.com.ua/), [wss://tracker.webtorrent.dev](https://webtorrent.dev/), [wss://tracker.openwebtorrent.com](https://openwebtorrent.com/)
86
89
  - STUN servers - [Public STUN server list](https://gist.github.com/mondain/b0ec1cf5f60ae726202e)
87
90
 
91
+ ## Reduce the Bundle Size
92
+
93
+ These steps apply when you bundle the npm packages yourself, with Vite, webpack, Rollup or esbuild. The prebuilt bundles in each package's `dist/` folder already include them.
94
+
95
+ - **Use the browser's XML parser (MPEG-DASH only).** The MPEG-DASH manifest parser is published for Node and browsers alike, so it imports a complete XML parser, `@xmldom/xmldom`. Every browser already has one. Point that import at `p2p-media-loader-core/shims/xmldom`, which exports the browser's `DOMParser`. This removes about 23 KB, gzipped.
96
+ - **Leave out the diagnostics ledger.** The packages contain a ledger of open resources that is used in testing, and it is off unless you turn it on (see [Diagnostics](#diagnostics) below). Define `__P2PML_DIAGNOSTICS__` as `false` to remove it. This removes about 1.5 KB, gzipped.
97
+
98
+ Vite:
99
+
100
+ ```js
101
+ // vite.config.js
102
+ export default {
103
+ resolve: {
104
+ alias: { "@xmldom/xmldom": "p2p-media-loader-core/shims/xmldom" },
105
+ },
106
+ define: { __P2PML_DIAGNOSTICS__: "false" },
107
+ };
108
+ ```
109
+
110
+ webpack, in a CommonJS config — name the file `webpack.config.cjs` in a project with `"type": "module"`:
111
+
112
+ ```js
113
+ // webpack.config.js
114
+ const webpack = require("webpack");
115
+
116
+ module.exports = {
117
+ resolve: {
118
+ alias: { "@xmldom/xmldom$": "p2p-media-loader-core/shims/xmldom" },
119
+ },
120
+ plugins: [new webpack.DefinePlugin({ __P2PML_DIAGNOSTICS__: "false" })],
121
+ };
122
+ ```
123
+
124
+ Things to know:
125
+
126
+ - Use the alias in browser builds only. The replacement reads `window.DOMParser` when it loads, so keep the real package for code that runs in Node, for example in server-side rendering.
127
+ - The alias applies to every package in your build that imports `@xmldom/xmldom`. Each of them then gets the browser's parser, which has the same `parseFromString` method.
128
+ - Do not alias the Babel helper `@babel/runtime/helpers/extends` that the HLS parser imports. Other packages load it with `require()`, which needs the original module, and it is only a few hundred bytes.
129
+ - You do not need to choose a protocol. The HLS.js integration includes only the HLS parser, and the dash.js integration only the MPEG-DASH parser. The Shaka and Video.js integrations include both, because those players play both.
130
+
131
+ ## Diagnostics
132
+
133
+ The ledger records each resource the library opens and closes — loaders, peers, tracker sockets, timers, storage and player hooks — with counters of results, and anomalies such as a timer that fires after its owner was destroyed. It is off by default, and costs almost nothing while off.
134
+
135
+ To turn it on, set the `debug` namespace before the page loads, then reload. The decision is made once, at the ledger's first record, so turning it on later in the same page has no effect:
136
+
137
+ ```js
138
+ localStorage.debug = "p2pml:diagnostics";
139
+ ```
140
+
141
+ The ledger appears on `window` at that first record, so read it once a player has started:
142
+
143
+ ```js
144
+ const snapshot = window.__p2pmlDiagnostics.snapshot();
145
+ // snapshot.live: open resources by kind; snapshot.open: each open resource;
146
+ // snapshot.counters: results; snapshot.probes: values read for the snapshot;
147
+ // snapshot.anomalies: states that must not occur
148
+ window.__p2pmlDiagnostics.clearAnomalies();
149
+ ```
150
+
151
+ The ledger is in the npm packages unless your build defines `__P2PML_DIAGNOSTICS__` as `false`. The prebuilt bundles in `dist/` leave it out.
152
+
88
153
  ## Key Components of the P2P Network
89
154
 
90
155
  All the components of the P2P network are free and open-source.
@@ -94,15 +159,15 @@ All the components of the P2P network are free and open-source.
94
159
  **P2P Media Loader** required browser features are:<br>
95
160
 
96
161
  - [WebRTC Data Channels](https://caniuse.com/mdn-api_rtcdatachannel) to exchange data between peers
97
- - [Media Source Extensions](https://caniuse.com/mediasource) or [Managed Media Source](https://caniuse.com/mdn-api_managedmediasource) are required by Hls.js and Shaka Player engines for media playback
162
+ - [Media Source Extensions](https://caniuse.com/mediasource) or [Managed Media Source](https://caniuse.com/mdn-api_managedmediasource) are required by HLS.js and Shaka Player engines for media playback
98
163
 
99
164
  [**STUN**](https://en.wikipedia.org/wiki/STUN) server is used by [WebRTC](https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API) to gather [ICE](https://en.wikipedia.org/wiki/Interactive_Connectivity_Establishment) candidates.
100
165
  There are many running public servers available on [Public STUN server list](https://gist.github.com/mondain/b0ec1cf5f60ae726202e).
101
166
 
102
167
  A compatible [**WebTorrent**](https://webtorrent.io/) tracker is required for WebRTC signaling and to create swarms of peers downloading the same media stream.
103
- A few running public trackers are available: [wss://tracker.webtorrent.dev](https://webtorrent.dev/), [wss://tracker.openwebtorrent.com](https://openwebtorrent.com/).
168
+ A few running public trackers are available: [wss://tracker.novage.com.ua](https://novage.com.ua/), [wss://tracker.webtorrent.dev](https://webtorrent.dev/), [wss://tracker.openwebtorrent.com](https://openwebtorrent.com/).
104
169
 
105
- It is possible to run personal WebTorrent tracker using open-source implementations: [wt-tracker](https://github.com/Novage/wt-tracker), [Aquatic](https://github.com/greatest-ape/aquatic), [OpenWebtorrent Tracker](https://github.com/OpenWebTorrent/openwebtorrent-tracker), [bittorrent-tracker](https://github.com/webtorrent/bittorrent-tracker).
170
+ It is possible to run personal WebTorrent tracker using open-source implementations: [wt-tracker-rust](https://github.com/Novage/wt-tracker-rust) (recommended), [wt-tracker](https://github.com/Novage/wt-tracker), [Aquatic](https://github.com/greatest-ape/aquatic), [OpenWebtorrent Tracker](https://github.com/OpenWebTorrent/openwebtorrent-tracker), [bittorrent-tracker](https://github.com/webtorrent/bittorrent-tracker).
106
171
 
107
172
  **P2P Media Loader** is configured to use public **STUN** and **WebTorrent** servers by default. It means that it is not required to run any server-side software for the P2P network to function for simple use cases.
108
173
 
@@ -116,4 +181,6 @@ Subsequently, **P2P Media Loader** transmits media stream details and connection
116
181
 
117
182
  **P2P Media Loader** then connects with these peers to download additional media segments and simultaneously shares segments that it has already downloaded.
118
183
 
119
- Periodically, random peers in the P2P swarm download new segments over HTTP(S) and distribute them to others via P2P.
184
+ A segment the player asks for while its buffer is low is fetched over HTTP(S) at once, so a player with **P2P Media Loader** is never slower than without it. With more buffer, the request waits for a peer that has the segment while the buffer drains.
185
+
186
+ Periodically, peers in the P2P swarm download segments the swarm does not hold yet over HTTP(S) and distribute them to others via P2P. Each such segment has one elected owner among the connected peers: every peer scores itself and its neighbours for that segment, and the lowest score fetches. Ownership rotates from segment to segment, so no peer is the swarm's permanent origin.