@slashedcloud/player
Version:
A media player application utilizing Shaka Player for adaptive video streaming, capable of playing HLS, MPD and plain HTTP video streams.
102 lines (101 loc) • 3.65 kB
JavaScript
var y = Object.defineProperty, v = Object.defineProperties;
var N = Object.getOwnPropertyDescriptors;
var w = Object.getOwnPropertySymbols;
var j = Object.prototype.hasOwnProperty, P = Object.prototype.propertyIsEnumerable;
var d = (n, o, t) => o in n ? y(n, o, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[o] = t, p = (n, o) => {
for (var t in o || (o = {}))
j.call(o, t) && d(n, t, o[t]);
if (w)
for (var t of w(o))
P.call(o, t) && d(n, t, o[t]);
return n;
}, f = (n, o) => v(n, N(o));
var l = (n, o, t) => d(n, typeof o != "symbol" ? o + "" : o, t);
var g = (n, o, t) => new Promise((s, r) => {
var i = (a) => {
try {
e(t.next(a));
} catch (h) {
r(h);
}
}, c = (a) => {
try {
e(t.throw(a));
} catch (h) {
r(h);
}
}, e = (a) => a.done ? s(a.value) : Promise.resolve(a.value).then(i, c);
e((t = t.apply(n, o)).next());
});
import E from "./Base.js";
import { P as m, S as u } 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 O extends E {
constructor(t, s) {
super(t);
l(this, "name", "ErrorTrackerPlugin");
l(this, "options");
this.options = s;
}
setup() {
return g(this, null, function* () {
const t = this.options.rate && this.options.rate > 0 && this.options.rate <= 1 ? this.options.rate : 0.1, s = this.options.method || "POST", r = new Headers();
if (this.options.headers)
for (const i in this.options.headers) {
const c = i.trim(), e = this.options.headers[i].trim();
!c || typeof c != "string" || !e || typeof e != "string" || r.append(c, e);
}
window.onunhandledrejection = (i) => {
var e;
const c = new m(this.name, u.WARNING, "Unhandled Rejection", {
description: "An unhandled rejection occurred.",
reason: i.reason
});
this.handleError(t, s, r, p(p({}, (e = this.options) == null ? void 0 : e.params), c.toObject()));
}, window.onerror = (i) => {
var e;
const c = new m(this.name, u.WARNING, `${i}`, {
description: "Window error occurred."
});
this.handleError(t, s, r, p(p({}, (e = this.options) == null ? void 0 : e.params), c.toObject()));
};
});
}
handleError(t, s, r, i) {
if ((t == 1 ? 1 : Math.random()) <= t && this.options.url) {
const e = this.convertBody(r, JSON.stringify(i));
fetch(this.options.url, { method: s, headers: r, body: e }).catch((a) => {
new m(this.name, u.WARNING, a.message, f(p({
description: "An error occurred while sending the error to the server."
}, a), {
reason: a
}));
});
}
window.gtag && this.options.event && window.gtag("event", this.player.elementId, p({ type: this.options.event }, i));
}
/**
* Convert Body depending on the Content-Type
* When the content type is null
* @param {Headers} headers - The headers to check for the Content-Type
* @param {string} body - The body to convert
* @returns {URLSearchParams | string} - The converted body
*/
convertBody(t, s) {
const r = t.get("Content-Type");
switch (r) {
case "application/x-www-form-urlencoded":
return new URLSearchParams({ log: s });
case "application/json":
default:
return r || t.append("Content-Type", "application/json"), JSON.stringify({ log: s });
}
}
}
export {
O as default
};