This module wraps dash.js
to bootstrap it with the Streamroot P2P module.
It provides a bundle that extends the dash.js
MediaPlayer
constructor to create a fully configured player which will use the Streamroot P2P module, giving you the exact same API.
You can integrate this bundle with minimal changes in your application. The bundled version of dash.js is a fork of v2.4.1. This fork includes a fix for live SegmentTimeline streams (see dash.js issue).
It also provides a wrapper that allows you to create/configure a player with a specific version of dash.js
. Minimum supported version of dash.js is v2.2.0.
You can install the artifacts distributed as NPM modules:
For the wrapper with dash.js included:
npm install streamroot-dashjs-p2p-bundle
For the wrapper without dash.js:
npm install streamroot-dashjs-p2p-wrapper
In your application import/require the package you want to use as in the example like
import DashjsP2PBundle from 'streamroot-dashjs-p2p-bundle';
or
import DashjsWrapper from 'streamroot-dashjs-p2p-wrapper';
Make sure you are using a Node.js version >= 6.0.0.
git clone https://github.com/streamroot/dashjs-p2p-wrapper.git
npm install
npm run build
The results will be in the destination folders dist/wrapper
and dist/bundle
.
To build and compile-watch development/debug versions use npm run wrapper_dev
or npm run bundle_dev
for wrapper and bundle respectively.
For running unit tests (in node.js), use
npm test
Include the bundle build in your app.
<head>
<!-- path to dashjs-p2p-bundle build -->
<script src="dashjs-p2p-bundle.js"></script>
</head>
Use the MediaPlayer bundle factory provided by dashjs-p2p-bundle
to create dash.js player.
var p2pConfig = {
streamrootKey: YOUR_STREAMROOT_KEY_HERE
};
var player = DashjsP2PBundle.MediaPlayer().create(p2pConfig);
var videoElementId = "videoPlayer";
var videoElement = document.getElementById(videoElementId);
var manifestURL = "example.mpd";
var autoStart = true;
player.initialize(videoElement, url, autoStart);
Include the wrapper build and dash.js build in your app.
<head>
<!-- path to dashjs-p2p-wrapper build -->
<script src="dashjs-p2p-wrapper.js"></script>
<!-- dash.js build of your choice starting from version 2.2.0 and higher -->
<script src="dash.all.debug.js"></script>
</head>
Create a dash.js MediaPlayer instance. Create wrapper instance, passing dash.js player, p2pConfig
and liveDelay
value as constructor params. Recommended liveDelay
value is 30 seconds.
var player = dashjs.MediaPlayer().create();
var p2pConfig = {
streamrootKey: YOUR_STREAMROOT_KEY_HERE
};
var liveDelay = 30;
var dashjsWrapper = new DashjsWrapper(player, p2pConfig, liveDelay);
var videoElementId = "videoPlayer";
var videoElement = document.getElementById(videoElementId);
var manifestURL = "example.mpd";
var autoStart = true;
player.initialize(videoElement, manifestURL, autoStart);
To see full sample code and extended possibilities of how to use this module, take a look at the code in the example
directory.
If you want to test the wrapper with a specific version of Dash.js, you could generate an example page with a specific version of Dash.js using:
npm run generate_example -- <Dash.js version>
For example npm run generate_example -- 2.4.0
will generate example2.4.0.wrapper.html
with Dash.js 2.4.0
instead of the bundled Dash.js 2.3.0
.
Specify your streamrootKey
in the p2pConfig
object. If you don't have it, go to Streamroot's dashboard and sign up. It's free. You can check other p2pConfig
options in the documentation.
Not available yet.
A peerAgent
public API is exposed on a DashjsWrapper
instance -- wrapper.peerAgent
.
List of peerAgent's public API getters/setters is documented here https://streamroot.readme.io/docs/peeragent-class-reference.
Start a local server like http-server
or node-static
in the project root, on port 8080 if you like.
Now visit http://localhost:8080/example/bundle.html for bundle demo or http://localhost:8080/example/wrapper.html for wrapper demo.
To see some p2p traffic open several browser tabs/windows playing the same manifest (so there will be peers to exchange p2p traffic).
The module is integrated in the following players: