stream-api/script.js
2021-05-12 10:53:33 +02:00

24 lines
827 B
JavaScript

document.addEventListener("DOMContentLoaded", () => {
let bodies = document.getElementsByTagName("body");
if(bodies.length === 1) {
let body = bodies[0];
let xhr = new XMLHttpRequest();
let upstream = "{{ stream }}";
xhr.addEventListener("load", () => {
let video = document.createElement("video");
video.id = "video-player";
video.className = "video-js";
body.appendChild(video);
let ctype = xhr.getResponseHeader("Content-Type");
console.log(ctype);
let player = videojs("video-player");
let source = {};
source.type = ctype;
source.src = upstream;
player.src(source);
});
xhr.open("HEAD", upstream, true);
xhr.send();
}
});