2021-05-14 10:54:53 +00:00
|
|
|
(() => {
|
2021-05-31 10:59:25 +00:00
|
|
|
const info = {% raw info %};
|
2021-05-20 15:02:45 +00:00
|
|
|
const handle = () => {
|
|
|
|
const [body] = document.getElementsByTagName("body");
|
|
|
|
const video = document.createElement("video");
|
|
|
|
video.className = "video-js vjs-big-play-centered";
|
|
|
|
body.appendChild(video);
|
|
|
|
const options = {};
|
|
|
|
options.controls = true;
|
|
|
|
options.liveui = true;
|
|
|
|
options.responsive = true;
|
|
|
|
options.fill = true;
|
|
|
|
options.techOrder = ["chromecast", "html5"];
|
|
|
|
options.plugins = {};
|
|
|
|
options.plugins.chromecast = {};
|
2021-05-21 08:58:13 +00:00
|
|
|
options.plugins.chromecast.addButtonToControlBar = false;
|
2021-05-20 15:02:45 +00:00
|
|
|
const player = videojs(video, options);
|
2022-02-13 13:15:33 +00:00
|
|
|
if(info.poster) {
|
2021-05-31 10:59:25 +00:00
|
|
|
player.poster(info.poster);
|
2021-05-25 07:54:54 +00:00
|
|
|
}
|
2021-05-20 15:02:45 +00:00
|
|
|
const source = {};
|
2021-05-31 10:59:25 +00:00
|
|
|
source.type = info.ctype;
|
|
|
|
source.src = info.upstream;
|
2021-05-20 15:02:45 +00:00
|
|
|
player.src(source);
|
2022-02-05 22:39:23 +00:00
|
|
|
|
2021-05-31 10:59:25 +00:00
|
|
|
const canPlayTypeRaw = player.canPlayType(info.ctype);
|
2021-05-25 06:44:20 +00:00
|
|
|
const canPlayType = (canPlayTypeRaw === "maybe") || (canPlayTypeRaw === "probably");
|
|
|
|
if(canPlayType) {
|
|
|
|
const Button = videojs.getComponent("Button");
|
|
|
|
const cbutton = {};
|
|
|
|
cbutton.clickHandler = (ev) => {
|
|
|
|
player.trigger("chromecastRequested");
|
|
|
|
}
|
|
|
|
cbutton.text = "Chromecast";
|
2021-05-23 20:02:33 +00:00
|
|
|
|
2022-02-05 22:39:23 +00:00
|
|
|
const dbutton = {};
|
2022-02-13 14:47:15 +00:00
|
|
|
dbutton.text = "Download";
|
2022-02-05 22:39:23 +00:00
|
|
|
dbutton.clickHandler = (ev) => {
|
2022-02-13 14:47:15 +00:00
|
|
|
if(info.download) {
|
|
|
|
window.open(info.download);
|
|
|
|
}
|
2022-02-05 22:39:23 +00:00
|
|
|
}
|
|
|
|
|
2021-06-10 10:23:55 +00:00
|
|
|
const bigCastButtonWrapper = new Button(player, cbutton);
|
2022-02-05 22:39:23 +00:00
|
|
|
const bigDownloadButtonWrapper = new Button(player, dbutton);
|
|
|
|
|
2021-06-10 10:23:55 +00:00
|
|
|
const bigCastButton = bigCastButtonWrapper.el();
|
2022-02-05 22:39:23 +00:00
|
|
|
const bigDownloadButton = bigDownloadButtonWrapper.el();
|
2021-06-10 10:23:55 +00:00
|
|
|
for(const elem of bigCastButton.children) {
|
|
|
|
bigCastButton.removeChild(elem);
|
|
|
|
}
|
2022-02-05 22:39:23 +00:00
|
|
|
|
|
|
|
for(const elem of bigDownloadButton.children) {
|
|
|
|
bigDownloadButton.removeChild(elem);
|
|
|
|
}
|
|
|
|
|
2021-06-10 10:23:55 +00:00
|
|
|
bigCastButton.classList.add("vjs-control");
|
|
|
|
bigCastButton.classList.add("vjs-button");
|
|
|
|
bigCastButton.classList.add("fab");
|
|
|
|
bigCastButton.classList.add("fa-chromecast");
|
|
|
|
bigCastButton.classList.add("vjs-big-chromecast");
|
|
|
|
player.addChild(bigCastButtonWrapper);
|
2022-02-05 22:39:23 +00:00
|
|
|
|
2022-02-13 13:15:33 +00:00
|
|
|
if(info.download) {
|
2022-02-05 22:39:23 +00:00
|
|
|
bigDownloadButton.classList.add("vjs-control");
|
|
|
|
bigDownloadButton.classList.add("vjs-button");
|
|
|
|
bigDownloadButton.classList.add("fas");
|
|
|
|
bigDownloadButton.classList.add("fa-download");
|
|
|
|
bigDownloadButton.classList.add("vjs-big-download");
|
|
|
|
player.addChild(bigDownloadButtonWrapper);
|
|
|
|
}
|
|
|
|
|
2021-05-25 06:44:20 +00:00
|
|
|
player.one("error", () => {
|
2021-06-10 10:23:55 +00:00
|
|
|
player.removeChild(bigCastButtonWrapper);
|
2022-02-13 13:15:33 +00:00
|
|
|
if(info.download) {
|
2022-02-05 22:39:23 +00:00
|
|
|
player.removeChild(bigDownloadButtonWrapper);
|
|
|
|
}
|
2021-05-25 06:44:20 +00:00
|
|
|
});
|
2021-05-21 12:19:12 +00:00
|
|
|
|
2021-05-25 06:44:20 +00:00
|
|
|
player.one("play", () => {
|
2021-06-10 10:23:55 +00:00
|
|
|
player.removeChild(bigCastButtonWrapper);
|
2022-02-13 14:47:15 +00:00
|
|
|
if(info.download) {
|
2022-02-05 22:39:23 +00:00
|
|
|
player.removeChild(bigDownloadButtonWrapper);
|
|
|
|
}
|
2021-05-25 06:44:20 +00:00
|
|
|
});
|
2021-05-25 06:23:25 +00:00
|
|
|
|
2021-06-10 10:23:55 +00:00
|
|
|
const smallCastButtonWrapper = new Button(player, cbutton);
|
|
|
|
const smallCastButton = smallCastButtonWrapper.el();
|
|
|
|
smallCastButton.classList.add("vjs-control");
|
|
|
|
smallCastButton.classList.add("vjs-button");
|
|
|
|
|
|
|
|
for(const elem of smallCastButton.children) {
|
|
|
|
if(elem.classList.contains("vjs-icon-placeholder")) {
|
|
|
|
elem.classList.add("fab");
|
|
|
|
elem.classList.add("fa-chromecast");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
player.controlBar.addChild(smallCastButtonWrapper);
|
|
|
|
|
2021-05-25 06:44:20 +00:00
|
|
|
player.on("chromecastConnected", () => {
|
|
|
|
if(player.volume() > 0.3) {
|
|
|
|
player.volume(0.2);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-05-12 07:50:51 +00:00
|
|
|
}
|
2021-05-31 10:59:25 +00:00
|
|
|
document.addEventListener("DOMContentLoaded", handle);
|
2021-05-14 10:54:53 +00:00
|
|
|
})();
|