@slashedcloud/player
Version:
A media player application utilizing Shaka Player for adaptive video streaming, capable of playing HLS, MPD and plain HTTP video streams.
111 lines (110 loc) • 3.6 kB
JavaScript
var A = Object.defineProperty, O = Object.defineProperties;
var b = Object.getOwnPropertyDescriptors;
var y = Object.getOwnPropertySymbols;
var S = Object.prototype.hasOwnProperty, k = Object.prototype.propertyIsEnumerable;
var R = (s) => {
throw TypeError(s);
};
var f = (s, t, e) => t in s ? A(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e, l = (s, t) => {
for (var e in t || (t = {}))
S.call(t, e) && f(s, e, t[e]);
if (y)
for (var e of y(t))
k.call(t, e) && f(s, e, t[e]);
return s;
}, v = (s, t) => O(s, b(t));
var h = (s, t, e) => f(s, typeof t != "symbol" ? t + "" : t, e), x = (s, t, e) => t.has(s) || R("Cannot " + e);
var u = (s, t, e) => t.has(s) ? R("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(s) : t.set(s, e);
var E = (s, t, e) => (x(s, t, "access private method"), e);
var w = (s, t, e) => new Promise((o, i) => {
var n = (r) => {
try {
d(e.next(r));
} catch (p) {
i(p);
}
}, a = (r) => {
try {
d(e.throw(r));
} catch (p) {
i(p);
}
}, d = (r) => r.done ? o(r.value) : Promise.resolve(r.value).then(n, a);
d((e = e.apply(s, t)).next());
});
import G from "./Base.js";
import { P as c, S as g } 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 m, P;
class N extends G {
/**
* Creates an instance of AnalyticsFeature.
* @param {Player} player - The player instance.
*/
constructor(e, o) {
super(e);
u(this, m);
h(this, "name", "AnalyticsPlugin");
h(this, "params", {});
h(this, "options");
this.options = o;
}
/**
* Sets up the AnalyticsFeature.
*/
setup() {
return w(this, null, function* () {
for (const e of this.options)
E(this, m, P).call(this, e);
});
}
/**
* Sends an event to the analytics provider.
* @param {string} event - The name of the event.
* @param Record<string, string | number> options - The options for the provider.
*/
sendEvent(e, o, i) {
return w(this, null, function* () {
let n = "Analytics", a;
switch (e) {
case "google":
n = "Google analytics", a = v(l(l({}, this.params[e]), i), { type: o }), window.gtag("event", this.player.elementId, l({}, a));
break;
default:
throw new c(this.name, g.ERROR, "Provider is not defined");
}
this.player.options.debug && (console.log(`======= ${n} event debug =======`), console.log(`Event sent: ${o} with options:`, l({}, a)));
});
}
}
m = new WeakSet(), /**
* Sets the provider for analytics.
* @param {AnalyticsPluginOption} options - The options for the provider.
* @private
*/
P = function(e) {
const o = e.provider;
switch (o) {
case "google":
if (!window.gtag) throw new c(this.name, g.ERROR, "Google tag is not loaded");
break;
default:
throw new c(this.name, g.ERROR, "Provider is not defined");
}
if (!Array.isArray(e.events) || !e.events.length)
throw new c(this.name, g.ERROR, "Events are not defined");
e.params && (this.params[o] = e.params), this.player.on(e.events, (i, n) => {
if (i === "error" && n.errorReason) {
const { code: a, message: d, name: r } = n.errorReason;
n.errorReason = JSON.stringify({ code: a, message: d, name: r });
}
this.sendEvent(o, i, l({}, n));
});
};
export {
N as default
};