stream-api/frontend/script.js

60 lines
2.0 KiB
JavaScript
Raw Normal View History

2021-05-14 10:54:53 +00:00
(() => {
2021-05-14 11:00:16 +00:00
let upstream = "{{ stream }}";
2021-05-14 10:54:53 +00:00
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) {
2021-05-14 11:00:16 +00:00
let body = bodies[0];
2021-05-12 08:26:15 +00:00
let video = document.createElement("video");
2021-05-12 14:40:10 +00:00
video.className = "video-js vjs-big-play-centered";
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;
2021-05-12 14:40:10 +00:00
options.responsive = true;
2021-05-12 14:51:42 +00:00
options.fill = true;
2021-05-12 14:03:39 +00:00
options.techOrder = ["chromecast", "html5"];
options.plugins = {};
options.plugins.chromecast = {};
2021-05-19 07:19:10 +00:00
options.plugins.chromecast.requestTitleFn = (src) => {
2021-05-19 07:21:34 +00:00
return "{% raw title %}";
2021-05-19 06:55:20 +00:00
}
2021-05-12 12:22:12 +00:00
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-19 13:54:42 +00:00
let Button = videojs.getComponent("Button");
let cbutton = {};
cbutton.clickHandler = (ev) => {
videojs.log("clicked");
}
let button = new Button(player, cbutton);
button.addClass("fab");
button.addClass("fa-chromecast");
button.addClass("vjs-control");
button.addClass("vjs-button");
button.addClass("vjs-big-chromecast");
player.addChild(button);
player.one("play", (ev) => {
player.removeChild(button);
});
2021-05-14 10:54:53 +00:00
}
2021-05-12 07:50:51 +00:00
}
2021-05-14 10:54:53 +00:00
document.addEventListener("DOMContentLoaded", handleCount);
xhr.addEventListener("load", handleCount);
})();