stream-api/script.js

25 lines
848 B
JavaScript
Raw Normal View History

2021-05-12 07:50:51 +00:00
document.addEventListener("DOMContentLoaded", () => {
2021-05-12 08:26:15 +00:00
let bodies = document.getElementsByTagName("body");
if(bodies.length === 1) {
let body = bodies[0];
let xhr = new XMLHttpRequest();
2021-05-12 08:53:33 +00:00
let upstream = "{{ stream }}";
xhr.addEventListener("load", () => {
2021-05-12 08:26:15 +00:00
let video = document.createElement("video");
2021-05-12 12:29:50 +00:00
body.appendChild(video);
2021-05-12 08:26:15 +00:00
let ctype = xhr.getResponseHeader("Content-Type");
2021-05-12 08:53:33 +00:00
console.log(ctype);
2021-05-12 10:27:51 +00:00
let options = {};
options.controls = true;
2021-05-12 12:22:12 +00:00
options.liveui = true;
let player = videojs(video, options);
2021-05-12 08:26:15 +00:00
let source = {};
source.type = ctype;
2021-05-12 08:53:33 +00:00
source.src = upstream;
2021-05-12 08:26:15 +00:00
player.src(source);
2021-05-12 08:46:10 +00:00
});
2021-05-12 08:53:33 +00:00
xhr.open("HEAD", upstream, true);
2021-05-12 08:26:15 +00:00
xhr.send();
2021-05-12 07:50:51 +00:00
}
});