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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
<script type="text/javascript" src="<?=h($assets)?>clapprio/dash-shaka-playback.min.js"></script>
<script type="text/javascript" src="<?=h($assets)?>clapprio/level-selector.min.js"></script>
<script type="text/javascript" src="<?=h($assets)?>clapprio/audio-selector.min.js"></script>
<div class="dashContainer">
<div id="player"></div>
</div>
<!--
this is an experimental hack, trying to protect the remaining page from
interference with the new dash-player.
-->
<script type="text/javascript">
(function(){
// Select relay from cdn url, retry indefinitely
var selectRelay = function(url, cb) {
$.ajax({
url: url,
cache: false,
dataType: "text",
timeout: 3000,
success: function(result, state, xhr) {
var relay = xhr.getResponseHeader("X-Host");
if (!relay)
setTimeout(selectRelay.bind(null, url, cb), 2000);
console.log("selected relay", relay);
var proto = url.match(/^https?:\/\//),
path = "/" + url.split("/").slice(3).join("/");
cb(proto + relay + path)
},
error: function(err) {
console.error("Error while selecting relay: ", err.status, err.statusText)
setTimeout(selectRelay.bind(null, url, cb), 2000);
}
});
}
var createPlayer = function(url) {
var player = new Clappr.Player({
source: url,
width: "100%",
plugins: [DashShakaPlayback, LevelSelector, AudioSelector],
shakaConfiguration: {
abr: {
defaultBandwidthEstimate: 600000
},
streaming: {
rebufferingGoal: 12,
jumpLargeGaps: true
}
},
levelSelectorConfig: {
labels: {
// HLS
0: 'Slides',
1: 'SD',
2: 'HD',
// DASH
7: 'HD',
8: 'SD',
9: 'Slides',
10: 'HD',
11: 'SD',
12: 'Slides',
13: 'HD',
14: 'SD',
15: 'Slides',
}
},
autoPlay: true,
parentId: '#player'
});
}
// Detect WebM capability, Select relay, Create player
var hasWebM = document.createElement('video').canPlayType('video/webm') != "";
var cdnUrl = hasWebM ? '<?=h($room->getDashManifestUrl())?>' : '<?=h($room->getHLSPlaylistUrl())?>';
selectRelay(cdnUrl, function(relayUrl) {
createPlayer(relayUrl);
});
}());
</script>
<style type="text/css">
#player > [data-player] {
padding-bottom: 56.25%;
height: auto !important;
}
body.room .player-wrap.tab-content {
padding: 0;
}
</style>
|