aboutsummaryrefslogtreecommitdiff
path: root/template/assemblies
diff options
context:
space:
mode:
authorAnton Schubert2017-12-26 15:13:57 +0100
committerMaZderMind2018-01-24 23:34:25 +0100
commit4996b0dbe9d984f15f4eaed735e9660aae1fe8e7 (patch)
tree428720a18a49777d45100b91ab06909ac900a8b2 /template/assemblies
parent4baa1827cdf4642bd67dd0bbd64b55eca9fe5f70 (diff)
add relay selection javascript for adaptive player
Diffstat (limited to 'template/assemblies')
-rw-r--r--template/assemblies/player/dash.phtml40
1 files changed, 37 insertions, 3 deletions
diff --git a/template/assemblies/player/dash.phtml b/template/assemblies/player/dash.phtml
index 54f685c..3ad61fd 100644
--- a/template/assemblies/player/dash.phtml
+++ b/template/assemblies/player/dash.phtml
@@ -11,9 +11,34 @@
interference with the new dash-player.
-->
<script type="text/javascript">
- var hasWebM = document.createElement('video').canPlayType('video/webm') != "";
- var player = new Clappr.Player({
- source: hasWebM ? '<?=h($room->getDashManifestUrl())?>' : '<?=h($room->getHLSPlaylistUrl())?>',
+(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: {
@@ -47,6 +72,15 @@
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>