JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 49
  • Score
    100M100P100Q115850F
  • License Apache-2.0

P2P Media Loader Shaka Player integration

Package Exports

  • p2p-media-loader-shaka

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (p2p-media-loader-shaka) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

P2P Media Loader - Shaka Player integration

npm version

P2P sharing of segmented media streams (i.e. HLS, DASH) using WebRTC for Shaka Player

Useful links:

Basic usage

General steps are:

  1. Include P2P Medial Loader scripts.
  2. Create P2P Medial Loader engine instance.
  3. Create a player instance.
  4. Call init function for the player.
<!DOCTYPE html>
<html lang="en">
<head>
    <title>Shaka Player with P2P Media Loader</title>
    <meta charset="utf-8">
    <script src="https://cdn.jsdelivr.net/npm/p2p-media-loader-core@latest/build/p2p-media-loader-core.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/p2p-media-loader-shaka@latest/build/p2p-media-loader-shaka.min.js"></script>
    <script src="https://github.com/videojs/mux.js/releases/download/v4.4.0/mux.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/shaka-player/2.4.4/shaka-player.compiled.js"></script>
</head>
<body>
    <video id="video" width="640" controls autoplay muted></video>
    <script>
        shaka.polyfill.installAll();
        if (shaka.Player.isBrowserSupported() && p2pml.shaka.Engine.isSupported()) {
            function onError(error) { console.error("Error code", error.code, "object", error); }

            var engine = new p2pml.shaka.Engine();

            var player = new shaka.Player(document.getElementById("video"));
            player.addEventListener("error", function(event) { onError(event.detail); });

            engine.initShakaPlayer(player);

            player.load("https://akamai-axtest.akamaized.net/routes/lapd-v1-acceptance/www_c4/Manifest.mpd").catch(onError);
        } else {
            document.write("Not supported :(");
        }
    </script>
</body>
</html>

API

The library uses window.p2pml.shaka as a root namespace in Web browser for:

  • Engine - Shaka Player support engine
  • version - API version

Engine

Shaka Player support engine.

Engine.isSupported()

Returns result from p2pml.core.HybridLoader.isSupported().

engine = new Engine([settings])

Creates a new Engine instance.

settings structure:

  • segments
    • forwardSegmentCount - Number of segments for building up predicted forward segments sequence; used to predownload and share via P2P. Default is 20;
    • maxHistorySegments - Maximum amount of requested segments manager should remember; used to build up sequence with correct priorities for P2P sharing. Default is 50;
    • swarmId - Override default swarm ID that is used to identify unique media stream with trackers (manifest URL without query parameters is used as the swarm ID if the parameter is not specified);
  • loader

engine.getSettings()

Returns engine instance settings.

engine.destroy()

Destroys engine; destroy loader and segment manager.

engine.initShakaPlayer(player)

Shaka Player integration.

player should be valid Shaka Player instance.

Example

shaka.polyfill.installAll();

var engine = new p2pml.shaka.Engine();

var video = document.getElementById("video");
var player = new shaka.Player(video);

engine.initShakaPlayer(player);

player.load("https://example.com/path/to/your/dash.mpd");