@slashedcloud/player
Version:
A media player application utilizing Shaka Player for adaptive video streaming, capable of playing HLS, MPD and plain HTTP video streams.
138 lines (136 loc) • 5.41 kB
JavaScript
var C = Object.defineProperty;
var g = (s) => {
throw TypeError(s);
};
var T = (s, e, t) => e in s ? C(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
var c = (s, e, t) => T(s, typeof e != "symbol" ? e + "" : e, t), v = (s, e, t) => e.has(s) || g("Cannot " + t);
var k = (s, e, t) => e.has(s) ? g("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(s) : e.set(s, t);
var y = (s, e, t) => (v(s, e, "access private method"), t);
var p = (s, e, t) => new Promise((r, n) => {
var h = (a) => {
try {
o(t.next(a));
} catch (d) {
n(d);
}
}, i = (a) => {
try {
o(t.throw(a));
} catch (d) {
n(d);
}
}, o = (a) => a.done ? r(a.value) : Promise.resolve(a.value).then(h, i);
o((t = t.apply(s, e)).next());
});
import S from "./Base.js";
import { P as l, S as m } from "../PlayerError-JebC7rsX.js";
import { s as w } from "../shaka-player.ui-CvkRFlcE.js";
import { i as P, h as $ } from "../HexRgb-Bi74b35C.js";
import { a as q } from "../Common-B3lKdzU9.js";
/*!
* SlashedCloud v0.1.2 (https://github.com/SlashedCloud/player#readme)
* Copyright 2024-2024 rogerio.jardim@fedrax.pt
* Licensed under Apache (https://github.com/SlashedCloud/player/blob/develop/LICENSE)
*/
var u, R, E;
class V extends S {
constructor(t, r) {
super(t);
k(this, u);
c(this, "name", "MarkerPlugin");
c(this, "markers", []);
c(this, "ready", !1);
c(this, "controlsContainer");
c(this, "options");
this.options = r, this.controlsContainer = this.player.controls.getControlsContainer();
}
setup() {
return p(this, null, function* () {
if (yield y(this, u, R).call(this, this.options), this.player.on("ready", () => {
this.ready = !0;
}), this.controlsContainer.addEventListener("markerShown", () => {
this.player.emit("markerShown");
}), this.controlsContainer.addEventListener("markerHidden", () => {
this.player.emit("markerHidden");
}), this.options.color && P(this.options.color)) {
const t = $(this.options.color);
document.documentElement.style.setProperty("--shaka-player-marker-color", t);
}
});
}
/**
* Set event listener to trigger show markers
*/
show(t) {
if (!this.ready) return;
this.controlsContainer.classList.add("shaka-keyboard-navigation", "markers-active"), this.controlsContainer.setAttribute("shown", "true");
const r = this.controlsContainer.querySelector(`[data-time="${t}"]`);
if (!r) throw new l(this.name, m.ERROR, `No element with time ${t} found`);
r.dispatchEvent(new CustomEvent("showMarker"));
}
/**
* Set event listener to trigger hide markers
*/
hide() {
this.ready && (this.controlsContainer.classList.contains("markers-active") && (this.controlsContainer.classList.remove("markers-active", "shaka-keyboard-navigation"), this.controlsContainer.setAttribute("shown", "false")), this.controlsContainer.dispatchEvent(new CustomEvent("hideMarker")));
}
secondsToVttTime(t) {
const r = Math.floor(t / 3600), n = Math.floor(t % 3600 / 60), h = (t % 60).toFixed(3);
return `${String(r).padStart(3, "0")}:${String(n).padStart(3, "0")}:${String(h).padStart(6, "0")}`;
}
// Convert File vtt to Marker
/**
* @param {string} uri
* @param {!shaka.net.NetworkingEngine} netEngine
* @param {shaka.extern.RetryParameters} retryParams
* @return {!Promise.<BufferSource>}
* @private
*/
getTextData_(t, r, n) {
return p(this, null, function* () {
const h = w.net.NetworkingEngine.RequestType.SEGMENT, i = w.net.NetworkingEngine.makeRequest([t], n);
return i.method = "GET", (yield r.request(h, i).promise).data;
});
}
}
u = new WeakSet(), R = function(t) {
return p(this, null, function* () {
let r = [];
if (t.src) {
const i = this.player.basePlayer.getConfiguration(), o = this.player.basePlayer.getNetworkingEngine();
if (!o)
throw new l(this.name, m.ERROR, "NetworkingEngine not found", {
reason: "NetworkingEngine is required for fetching markers"
});
const a = yield this.getTextData_(t.src, o, i.streaming.retryParameters), d = w.util.BufferUtils.toUint8(a), b = w.util.StringUtils.fromUTF8(d);
if (r = JSON.parse(b), !Array.isArray(r)) throw new l(this.name, m.ERROR, "Response data is not an array");
if (r.length === 0) throw new l(this.name, m.ERROR, "Response data is empty");
for (const f of r)
if (f.thumb) {
if (q(f.thumb)) continue;
f.thumb = new URL(f.thumb, t.src).href;
}
} else t.markers && (r = t.markers);
let n = `WEBVTT
`;
r.forEach((i, o) => {
if (!i.title) throw new l(this.name, m.ERROR, "Title is required for markers");
if (!i.time) throw new l(this.name, m.ERROR, "Time is required for markers");
if (!i.thumb) throw new l(this.name, m.ERROR, "Thumb is required for markers");
const a = this.secondsToVttTime(i.time);
n += `${o + 1}
`, n += `${a} --> ${a}
`, n += `${i.title.replace(/\n/g, "")}`, n += `#thumb#${i.thumb}
`, n += `
`;
});
const h = y(this, u, E).call(this, n);
yield this.player.basePlayer.addChaptersTrack(h, "markers", "text/vtt");
});
}, E = function(t) {
const r = new Blob([t], { type: "text/vtt" });
return URL.createObjectURL(r);
};
export {
V as default
};