stream-api/frontend/script.js
2021-05-14 13:00:16 +02:00

42 lines
1.3 KiB
JavaScript

(() => {
let upstream = "{{ stream }}";
let xhr = new XMLHttpRequest();
xhr.open("HEAD", upstream, true);
xhr.send();
let count = 2;
let handleCount = () => {
if(--count === 0) {
handle();
}
}
let handle = () => {
let bodies = document.getElementsByTagName("body");
if(bodies.length === 1) {
let body = bodies[0];
let video = document.createElement("video");
video.className = "video-js vjs-big-play-centered";
body.appendChild(video);
let ctype = xhr.getResponseHeader("Content-Type");
console.log(ctype);
let options = {};
options.controls = true;
options.liveui = true;
options.responsive = true;
options.fill = true;
options.techOrder = ["chromecast", "html5"];
options.plugins = {};
options.plugins.chromecast = {};
let player = videojs(video, options);
let source = {};
source.type = ctype;
source.src = upstream;
player.src(source);
}
}
document.addEventListener("DOMContentLoaded", handleCount);
xhr.addEventListener("load", handleCount);
})();