UNPKG

@slashedcloud/player

Version:

A media player application utilizing Shaka Player for adaptive video streaming, capable of playing HLS, MPD and plain HTTP video streams.

119 lines (116 loc) 4.43 kB
var P = Object.defineProperty; var g = (s) => { throw TypeError(s); }; var E = (s, r, t) => r in s ? P(s, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[r] = t; var T = (s, r, t) => E(s, typeof r != "symbol" ? r + "" : r, t), $ = (s, r, t) => r.has(s) || g("Cannot " + t); var u = (s, r, t) => r.has(s) ? g("Cannot add the same private member more than once") : r instanceof WeakSet ? r.add(s) : r.set(s, t); var h = (s, r, t) => ($(s, r, "access private method"), t); var y = (s, r, t) => new Promise((e, i) => { var o = (a) => { try { c(t.next(a)); } catch (p) { i(p); } }, l = (a) => { try { c(t.throw(a)); } catch (p) { i(p); } }, c = (a) => a.done ? e(a.value) : Promise.resolve(a.value).then(o, l); c((t = t.apply(s, r)).next()); }); import L from "./Base.js"; import { P as m, S as f } from "../PlayerError-JebC7rsX.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 n, R, b, w, d, v; class M extends L { /** * Creates an instance of the ChaptersFeature. * @param player The SlashedCloudPlayer instance. */ constructor(t, e) { super(t); u(this, n); T(this, "name", "ChaptersPlugin"); T(this, "options"); T(this, "fallbackLocale", "en"); this.options = e; } setup() { return y(this, null, function* () { if (!this.options || !Array.isArray(this.options)) throw new m(this.name, f.ERROR, "The options are missing or not clearly defined.", { description: "Provide the necessary options to complete the setup process." }); let t = this.options.find((o) => o.lang === this.player.language); if (!t && this.player.language !== this.fallbackLocale && (t = this.options.find((o) => o.lang === this.fallbackLocale)), !t) throw new m(this.name, f.ERROR, "Option Not Found for Current Language.", { description: "No options are available for the current language or fallback language." }); const { src: e, lang: i } = h(this, n, R).call(this, t); yield this.player.basePlayer.addChaptersTrack(e, i, "text/vtt"); }); } } n = new WeakSet(), R = function(t) { var i; const e = (i = t.lang) != null ? i : this.player.language; if (t.chapters) { if (!Array.isArray(t.chapters)) throw new m(this.name, f.ERROR, "The chapters options are missing or not clearly defined.", { description: "Provide the necessary options to complete the setup process." }); t.chapters.sort((c, a) => c.startTime - a.startTime); for (const c in t.chapters) { const a = t.chapters[c]; if (a.endTime && a.startTime > a.endTime && a.startTime < 0) throw new m(this.name, f.ERROR, `StartTime is bigger than endTime in ${c}`); } const o = h(this, n, b).call(this, t.chapters); return { src: h(this, n, v).call(this, o), lang: e }; } else { if (t.src) return { src: t.src, lang: e }; throw new m(this.name, f.ERROR, "`src` or `chapters` Not Provided", { description: "Please provide the necessary source or chapters to complete the setup process." }); } }, b = function(t) { let e = `WEBVTT `; for (const i in t) { const o = t[i]; if (o.startTime > this.player.videoElement.duration) continue; const l = h(this, n, d).call(this, o.startTime), c = t[parseInt(i) + 1], a = h(this, n, w).call(this, this.player.videoElement.duration, o.endTime, c == null ? void 0 : c.startTime); e += `${parseInt(i, 10) + 1} ${l} --> ${a} ${o.title} `; } return e; }, /** * Set time for chapters and check if the duration is bigger than maxDuration * @param maxDuration * @param duration * @param replaceDuration * @returns */ w = function(t, e, i) { return e && e <= t ? h(this, n, d).call(this, e) : i && i <= t ? h(this, n, d).call(this, i) : h(this, n, d).call(this, t); }, d = function(t) { const e = (a, p) => a.toString().padStart(p, "0"), i = e(Math.floor(t / 3600), 2), o = e(Math.floor(t % 3600 / 60), 2), l = e(Math.floor(t % 60), 2), c = e(Math.floor((t - Math.floor(t)) * 1e3), 3); return `${i}:${o}:${l}.${c}`; }, v = function(t) { const e = new Blob([t], { type: "text/vtt" }); return URL.createObjectURL(e); }; export { M as default };