forked from cdnbye/hlsjs-p2p-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick-start.html
More file actions
42 lines (42 loc) · 1.73 KB
/
quick-start.html
File metadata and controls
42 lines (42 loc) · 1.73 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
<script src="https://cdn.jsdelivr.net/npm/cdnbye@0.1.1"></script>
<video id="video" controls></video>
<p id="version"></p>
<h3>download info:</h3>
<p id="info"></p>
<table id="table-body">
<tbody ></tbody>
</table>
<script>
document.querySelector('#version').innerText = `hls.js version: ${Hls.version} cdnbye version: ${Hls.pluginVersion}`;
if(Hls.isSupported()) {
var video = document.getElementById('video');
var hls = new Hls();
hls.loadSource('https://video-dev.github.io/streams/x36xhzz/url_2/193039199_mp4_h264_aac_ld_7.m3u8');
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED,function(event, data) {
video.play();
});
var total = 0, p2p = 0;
hls.on(Hls.Events.FRAG_LOADED, (id, data) => {
var frag = data.frag;
console.log(`frag.loadByP2P ${frag.loadByP2P} frag.loadByHTTP ${frag.loadByHTTP}`)
var source = undefined;
if (frag.loadByHTTP === true) {
source = 'HTTP';
} else if (frag.loadByP2P === true) {
source = 'P2P';
}
addToTable(frag.relurl, frag.loaded, source);
total += frag.loaded;
if (source === 'P2P') p2p += frag.loaded;
document.querySelector('#info').innerText = `p2p ratio: ${Math.round(p2p/total*100)}% saved traffic: ${Math.round(p2p/1024)}KB`;
});
function addToTable(url, downloaded, source) {
var infoStr = `download ${url}(size:${downloaded}B) by ${source}`;
document.querySelector('#table-body tbody').innerHTML +=
`<tr style="text-align: center">
<td>${infoStr}</td>
</tr>`
};
}
</script>