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.

86 lines (85 loc) 3.4 kB
import '../AdOverlay.css';var y = Object.defineProperty; var u = (d, i, e) => i in d ? y(d, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : d[i] = e; var h = (d, i, e) => u(d, typeof i != "symbol" ? i + "" : i, e); var p = (d, i, e) => new Promise((t, s) => { var a = (n) => { try { r(e.next(n)); } catch (o) { s(o); } }, l = (n) => { try { r(e.throw(n)); } catch (o) { s(o); } }, r = (n) => n.done ? t(n.value) : Promise.resolve(n.value).then(a, l); r((e = e.apply(d, i)).next()); }); import g from "./Base.js"; import { P as f, S as k } 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) */ class w extends g { constructor(e, t) { super(e); h(this, "name", "AdOverlayPlugin"); h(this, "isAdPlaying", !1); h(this, "options"); this.options = t; } setup() { return p(this, null, function* () { var o, c; if (this.options.kind === "iframe" && !this.options.height) return; this.player.uiConfig.addBigPlayButton = !1; const e = document.createElement("div"); e.className = "shaka-modal-ad-overlay"; const t = document.createElement("div"); t.className = "shaka-modal-ad-content"; const s = this.setOverlay(this.options), a = document.createElement("button"); a.className = "shaka-ad-play-button"; const l = document.createElement("i"); l.classList.add("material-icons-round"), l.textContent = "play_arrow"; const r = (c = (o = this.player.localization) == null ? void 0 : o.resolve("PLAY")) != null ? c : "Play", n = document.createTextNode(r); a.appendChild(l), a.appendChild(n), a.addEventListener("click", () => { this.player.videoElement.play(); }), t.appendChild(s), t.appendChild(a), e.appendChild(t), this.player.container.appendChild(e), this.player.on(["adComplete", "adError", "adSkip", "pause", "play", "adStart"], (m) => { switch (m) { case "adComplete": case "adError": case "adSkip": case "play": this.isAdPlaying = !1; break; case "adStart": this.isAdPlaying = !0; break; } if (this.isAdPlaying || this.player.controls.isSeeking() || !this.player.videoElement.paused) return e.classList.add("shaka-hidden"); e.classList.remove("shaka-hidden"); }); }); } setOverlay(e) { switch (e.kind) { case "image": const t = document.createElement("img"); t.src = e.src; const s = document.createElement("a"); return s.href = e.link, s.target = "_blank", s.rel = "sponsored", this.options.width && (t.style.width = this.options.width + "px"), this.options.height && (t.style.height = this.options.height + "px"), s.appendChild(t), s; case "iframe": const a = document.createElement("iframe"); return a.src = e.src, this.options.width && (a.style.width = this.options.width + "px"), this.options.height && (a.style.height = this.options.height + "px"), a.scrolling = "no", a; default: throw new f(this.name, k.ERROR, "Invalid ad overlay kind"); } } } export { w as default };