stream-api/script.js
2021-05-12 17:14:39 +02:00

33 lines
1.1 KiB
JavaScript

let url = new URL("{{ stream }}", window.location.origin);
let upstream = url.href;
document.addEventListener("DOMContentLoaded", () => {
let bodies = document.getElementsByTagName("body");
if(bodies.length === 1) {
let body = bodies[0];
let xhr = new XMLHttpRequest();
xhr.addEventListener("load", () => {
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);
});
xhr.open("HEAD", upstream, true);
xhr.send();
}
});