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.

83 lines (82 loc) 2.6 kB
var g = Object.defineProperty, E = Object.defineProperties; var v = Object.getOwnPropertyDescriptors; var w = Object.getOwnPropertySymbols; var O = Object.prototype.hasOwnProperty, P = Object.prototype.propertyIsEnumerable; var l = (n, t, a) => t in n ? g(n, t, { enumerable: !0, configurable: !0, writable: !0, value: a }) : n[t] = a, m = (n, t) => { for (var a in t || (t = {})) O.call(t, a) && l(n, a, t[a]); if (w) for (var a of w(t)) P.call(t, a) && l(n, a, t[a]); return n; }, d = (n, t) => E(n, v(t)); var c = (n, t, a) => l(n, typeof t != "symbol" ? t + "" : t, a); var h = (n, t, a) => new Promise((i, s) => { var y = (o) => { try { r(a.next(o)); } catch (e) { s(e); } }, R = (o) => { try { r(a.throw(o)); } catch (e) { s(e); } }, r = (o) => o.done ? i(o.value) : Promise.resolve(o.value).then(y, R); r((a = a.apply(n, t)).next()); }); import T from "./Base.js"; import { P as p, S as f } from "../PlayerError-JebC7rsX.js"; import { i as u, a as b } 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) */ class x extends T { /** * Creates an instance of AccentColorFeature. * @param player - The SlashedCloudPlayer instance. */ constructor(a, i) { super(a); c(this, "name", "TranslationPlugin"); c(this, "options"); this.options = i; } setup() { return h(this, null, function* () { if (!this.player.localization) throw new p(this.name, f.ERROR, "Localization is not available"); if (this.options) { let a; const i = this.options[this.player.language]; if (!i) return; if (u(i)) a = i; else if (b(i)) a = yield this.loadTranslation(new URL(i)); else throw new p(this.name, f.ERROR, "Invalid data type"); const s = new Map(Object.entries(a)); this.player.localization.insert(this.player.language, s); } }); } loadTranslation(a) { return h(this, null, function* () { try { const i = yield fetch(a); if (!i.ok) throw new Error(`Failed to fetch translations from ${a}`); const s = yield i.json(); if (!u(s)) throw new Error("Invalid data received for translations"); return s; } catch (i) { throw new p(this.name, f.ERROR, i.message, d(m({}, i), { reason: i })); } }); } } export { x as default };