-
Notifications
You must be signed in to change notification settings - Fork 5
/
quick-start.html
29 lines (29 loc) · 1.34 KB
/
quick-start.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<html>
<video id="videoPlayer" controls></video>
<p id="version"></p>
<h3>download info:</h3>
<p id="peers"></p>
<p id="info"></p>
<script src="https://cdn.dashjs.org/v4.7.3/dash.all.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@swarmcloud/dashjs"></script>
<script>
var url = "https://dash.akamaized.net/akamai/bbb_30fps/bbb_30fps.mpd";
var player = dashjs.MediaPlayer().create()
document.querySelector('#version').innerText = `dash.js version: ${player.getVersion()} p2p version: ${P2PEngineDash.version}`;
var p2pConfig = {
logLevel: 'debug',
// trackerZone: 'hk', // if using Hongkong tracker
// trackerZone: 'us', // if using USA tracker
// token: YOUR_TOKEN
}
var engine = new P2PEngineDash(player, p2pConfig);
player.initialize(document.querySelector("#videoPlayer"), url, true);
engine.on('stats', function (stats) {
var total = stats.totalHTTPDownloaded + stats.totalP2PDownloaded;
document.querySelector('#info').innerText = `p2p ratio: ${Math.round(stats.totalP2PDownloaded / total * 100)}% saved traffic: ${Math.round(stats.totalP2PDownloaded)}KB upload: ${Math.round(stats.totalP2PUploaded)}KB`;
})
engine.on('peers', function (peers) {
document.querySelector('#peers').innerText = `peers: ${peers.length}`;
})
</script>
</html>