@meshstream/p2p-web 0.2.1 → 1.0.1

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
@@ -1,12 +1,15 @@
1
- # MeshStream P2P Web SDK
2
-
3
- Browser HLS and DASH P2P delivery SDK for MeshStream P2P-CDN. The SDK wraps
4
- `hls.js`, Shaka Player, and `p2p-media-loader`, fetches runtime configuration
5
- from Config API, joins a WebRTC tracker swarm, reports playback/P2P statistics,
6
- and keeps CDN playback as the fallback path.
7
-
8
- ## Install
9
-
1
+ # MeshStream P2P Web SDK
2
+
3
+ SDK-owned console diagnostics respect the client `logLevel` (default `none`), with redaction and
4
+ repeated-error limiting. Web does not write local log files. See the [logging guide](../../docs/sdk-logging.md).
5
+
6
+ Browser HLS and DASH P2P delivery SDK for MeshStream P2P-CDN. The SDK wraps
7
+ `hls.js`, Shaka Player, and `p2p-media-loader`, fetches runtime configuration
8
+ from Config API, joins a WebRTC tracker swarm, reports playback/P2P statistics,
9
+ and keeps CDN playback as the fallback path.
10
+
11
+ ## Install
12
+
10
13
  ```bash
11
14
  # SDK-managed player: MeshStream bundles its HLS, DASH, and P2P runtimes.
12
15
  npm install @meshstream/p2p-web
@@ -19,33 +22,33 @@ over its configuration or lifecycle:
19
22
  ```bash
20
23
  npm install @meshstream/p2p-web hls.js
21
24
  ```
22
-
23
- In this monorepo the SDK is consumed as a workspace package:
24
-
25
- ```bash
26
- npm run build:web-sdk
27
- npm run build -w @p2pcdn/web-demo
28
- ```
29
-
30
- ## Quick Start
31
-
32
- ```ts
25
+
26
+ In this monorepo the SDK is consumed as a workspace package:
27
+
28
+ ```bash
29
+ npm run build:web-sdk
30
+ npm run build -w @p2pcdn/web-demo
31
+ ```
32
+
33
+ ## Quick Start
34
+
35
+ ```ts
33
36
  import { attach } from "@meshstream/p2p-web";
34
37
 
35
38
  const player = attach({
36
- key: "your_sdk_key",
39
+ key: "your_sdk_key",
37
40
  url: "https://cdn.example.com/live/index.m3u8", // or .mpd / .mp4 / .mp3
38
41
  video: document.querySelector("video"),
39
- });
40
-
41
- await player.start();
42
-
42
+ });
43
+
44
+ await player.start();
45
+
43
46
  window.addEventListener("pagehide", () => player.dispose(), { once: true });
44
47
  ```
45
48
 
46
49
  The historic `video` option accepts any `HTMLMediaElement`; pass an `<audio>`
47
50
  element for progressive MP3 playback.
48
-
51
+
49
52
  The SDK fetches SaaS bootstrap configuration, selects trackers/reporting
50
53
  endpoints, detects browser capability, starts WebRTC P2P when possible, and
51
54
  keeps CDN playback as the automatic fallback path.
@@ -172,8 +175,8 @@ import it from `@meshstream/p2p-web/advanced`; standard integrations should
172
175
  continue to use root-level `attach`.
173
176
 
174
177
  For a plain video element:
175
-
176
- ```ts
178
+
179
+ ```ts
177
180
  import { attach } from "@meshstream/p2p-web";
178
181
 
179
182
  const player = attach({ key, url, video });
@@ -214,13 +217,13 @@ window.addEventListener("pagehide", () => {
214
217
 
215
218
  For rotating signed URLs, pass a stable business identity so viewers join the
216
219
  same swarm. `mimeType` is useful when the media URL has no `.m3u8`, `.mpd`, `.mp4`, or `.mp3`
217
- suffix. `originHeaders` are sent only to same-origin manifest, segment, and key requests on the
218
- configured media origin. SDK-controlled headers such as `Range` and hop-by-hop headers are ignored;
219
- the browser still applies its own forbidden-header and CORS rules. For Shaka and dash.js
220
- adapter objects, the player must expose its request interception API; otherwise
221
- the SDK fails explicitly instead of starting without the requested headers.
222
-
223
- ```ts
220
+ suffix. `originHeaders` are sent only to same-origin manifest, segment, and key requests on the
221
+ configured media origin. SDK-controlled headers such as `Range` and hop-by-hop headers are ignored;
222
+ the browser still applies its own forbidden-header and CORS rules. For Shaka and dash.js
223
+ adapter objects, the player must expose its request interception API; otherwise
224
+ the SDK fails explicitly instead of starting without the requested headers.
225
+
226
+ ```ts
224
227
  const player = attach({
225
228
  key,
226
229
  url: signedManifestUrl,
@@ -250,17 +253,17 @@ const player = attach({
250
253
  kind === "segment" ? { Authorization: `Bearer ${playbackToken}` } : undefined,
251
254
  });
252
255
  ```
253
-
256
+
254
257
  For Video.js:
255
-
256
- ```ts
258
+
259
+ ```ts
257
260
  import { attachToVideoJs } from "@meshstream/p2p-web/adapters";
258
-
261
+
259
262
  const player = attachToVideoJs({
260
- key,
261
- url,
262
- player: videojs("player"),
263
- });
263
+ key,
264
+ url,
265
+ player: videojs("player"),
266
+ });
264
267
  await player.start();
265
268
  ```
266
269
 
@@ -288,48 +291,48 @@ await session.start();
288
291
  ```
289
292
 
290
293
  For players built on top of a standard `<video>` element:
291
-
292
- ```ts
294
+
295
+ ```ts
293
296
  import { attachToArtPlayer, attachToDPlayer, attachToPlyr } from "@meshstream/p2p-web/adapters";
294
-
295
- await attachToPlyr({ key, url, player: plyr }).start();
296
- await attachToDPlayer({ key, url, player: dplayer }).start();
297
- await attachToArtPlayer({ key, url, player: art }).start();
298
- ```
299
-
297
+
298
+ await attachToPlyr({ key, url, player: plyr }).start();
299
+ await attachToDPlayer({ key, url, player: dplayer }).start();
300
+ await attachToArtPlayer({ key, url, player: art }).start();
301
+ ```
302
+
300
303
  The named adapters resolve common `video` or `media` fields, or a `<video>` nested
301
304
  inside the player's root element, and then use the
302
305
  same automatic HLS, DASH, and progressive-media path as the plain video adapter. They are media-element bridges,
303
306
  not native Video.js, Plyr, DPlayer, or ArtPlayer engine plugins: MeshStream
304
307
  owns the playback instance used for the supplied media element.
305
-
306
- For DASH with the standard SDK path:
307
-
308
- ```ts
308
+
309
+ For DASH with the standard SDK path:
310
+
311
+ ```ts
309
312
  import { attach } from "@meshstream/p2p-web";
310
313
 
311
314
  const player = attach({
312
- key,
313
- url: "https://cdn.example.com/live/index.mpd",
314
- video,
315
- });
316
- await player.start();
317
- ```
318
-
315
+ key,
316
+ url: "https://cdn.example.com/live/index.mpd",
317
+ video,
318
+ });
319
+ await player.start();
320
+ ```
321
+
319
322
  `attach` selects DASH for `.mpd` URLs and HLS for `.m3u8` URLs. Customers
320
- do not pass a protocol flag. DASH P2P uses Shaka Player internally for the
321
- standard SDK path.
322
-
323
- For an existing Shaka Player:
324
-
325
- ```ts
323
+ do not pass a protocol flag. DASH P2P uses Shaka Player internally for the
324
+ standard SDK path.
325
+
326
+ For an existing Shaka Player:
327
+
328
+ ```ts
326
329
  import { attachToShaka } from "@meshstream/p2p-web/adapters";
327
-
328
- const player = attachToShaka({
329
- key,
330
- url: "https://cdn.example.com/live/index.mpd",
331
- player: shakaPlayer,
332
- });
330
+
331
+ const player = attachToShaka({
332
+ key,
333
+ url: "https://cdn.example.com/live/index.mpd",
334
+ player: shakaPlayer,
335
+ });
333
336
  await player.start();
334
337
  ```
335
338
 
@@ -338,10 +341,10 @@ application retains ownership of the supplied Shaka instance and must destroy
338
341
  it when appropriate.
339
342
 
340
343
  For an existing dash.js player:
341
-
342
- ```ts
344
+
345
+ ```ts
343
346
  import { attachToDashJs } from "@meshstream/p2p-web/adapters";
344
-
347
+
345
348
  const player = attachToDashJs({
346
349
  key,
347
350
  url: "https://cdn.example.com/live/index.mpd",
@@ -392,29 +395,29 @@ audio/video fallback requests retain those headers; dynamic values override
392
395
  static values. Cross-origin media, text, DRM, non-contiguous ranges, and
393
396
  RxPlayer low-latency chunked loading remain on the customer's RxPlayer/CDN
394
397
  path without SDK-supplied headers.
395
-
396
- Telemetry keeps the playback host and path for diagnostics but strips query and fragment data,
397
- so signed playback credentials are not included in reports.
398
-
399
- ## Runtime Contract
400
-
401
- - `key` is the customer-facing SDK Key and can be embedded in Web pages.
398
+
399
+ Telemetry keeps the playback host and path for diagnostics but strips query and fragment data,
400
+ so signed playback credentials are not included in reports.
401
+
402
+ ## Runtime Contract
403
+
404
+ - `key` is the customer-facing SDK Key and can be embedded in Web pages.
402
405
  - `homeRegion` is resolved from the SDK Key and identifies the tenant's registered data-home
403
406
  region. It is returned by bootstrap for diagnostics and future regional routing; customer code
404
407
  cannot override it.
405
408
  - Request-network GeoIP is used only for access-side Tracker/ICE locality and is not a data-residency
406
409
  selection.
407
- - Customer integrations should only need `key`, the media `url`, and a `video`
408
- element for the standard Web path.
409
- - The SaaS bootstrap endpoint, tracker pool, ICE servers, reporting route, and
410
- scheduling policy are internal service configuration.
411
- - P2P, tracker, authorization, and reporting failures must not block `hls.js`
412
- playback.
413
- - `detectWebP2pCapability` should be called before constructing the P2P client.
414
- iOS Safari HLS without MSE is routed to native HLS CDN playback.
415
- - Fallback reporting uses the service-owned endpoint returned by bootstrap.
416
- - Signed CDN URL query fields such as `token`, `signature`, `expires`,
417
- `x-amz-*`, `x-oss-*`, and `x-goog-*` are excluded from URL-derived swarm IDs.
410
+ - Customer integrations should only need `key`, the media `url`, and a `video`
411
+ element for the standard Web path.
412
+ - The SaaS bootstrap endpoint, tracker pool, ICE servers, reporting route, and
413
+ scheduling policy are internal service configuration.
414
+ - P2P, tracker, authorization, and reporting failures must not block `hls.js`
415
+ playback.
416
+ - `detectWebP2pCapability` should be called before constructing the P2P client.
417
+ iOS Safari HLS without MSE is routed to native HLS CDN playback.
418
+ - Fallback reporting uses the service-owned endpoint returned by bootstrap.
419
+ - Signed CDN URL query fields such as `token`, `signature`, `expires`,
420
+ `x-amz-*`, `x-oss-*`, and `x-goog-*` are excluded from URL-derived swarm IDs.
418
421
  - `contentId` is optional. When supplied, the SDK derives the internal swarm ID
419
422
  from it so rotating signed URL paths remain in the same swarm; otherwise it
420
423
  derives identity from the canonical playback URL.
@@ -431,17 +434,17 @@ so signed playback credentials are not included in reports.
431
434
  `Accept-Ranges` through CORS, and allow `GET`, `HEAD`, `OPTIONS`, and the `Range` request header.
432
435
  `HEAD` is recommended; if the origin explicitly returns `405` or `501`, extensionless URL detection
433
436
  uses a one-byte range `GET` instead. Missing metadata or any P2P error falls back to the original CDN URL.
434
-
435
- ## Public API
436
-
437
- ```ts
437
+
438
+ ## Public API
439
+
440
+ ```ts
438
441
  // Standard customer-facing entry point
439
442
  attach(options)
440
443
 
441
444
  // Advanced player adapters
442
445
  import { attachToShaka, attachToDashJs, attachToVhs, attachToVideoJs } from "@meshstream/p2p-web/adapters";
443
-
444
- // P2P runtime controls
446
+
447
+ // P2P runtime controls
445
448
  player.start()
446
449
  player.dispose()
447
450
  player.setP2pEnabled(enabled)
@@ -480,15 +483,15 @@ Low-latency HLS/DASH partial CMAF segment requests remain on the player CDN
480
483
  path. P2P only distributes complete segments: sharing a response before its
481
484
  partial body is complete breaks player cancellation semantics and causes
482
485
  latency jitter. Playback continues normally through CDN for those parts.
483
-
484
- ## Release Checks
485
-
486
- ```bash
487
- npm test -w @meshstream/p2p-web
488
- npm run build:web-sdk:release
489
- npm run pack:dry-run -w @meshstream/p2p-web
490
- ```
491
-
486
+
487
+ ## Release Checks
488
+
489
+ ```bash
490
+ npm test -w @meshstream/p2p-web
491
+ npm run build:web-sdk:release
492
+ npm run pack:dry-run -w @meshstream/p2p-web
493
+ ```
494
+
492
495
  `prepack` runs the SDK test suite, bundles the runtime dependencies into the
493
496
  public entry points, and then minifies the release output before package
494
497
  creation. The published package contains only bundled JavaScript, `.d.ts`