UNPKG

p2p-media-loader-core

Version:
1,172 lines 161 kB
var os = Object.defineProperty; var as = (r, t, e) => t in r ? os(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e; var y = (r, t, e) => as(r, typeof t != "symbol" ? t + "" : t, e); class N extends Error { constructor(e, n) { super(n); y(this, "timestamp"); this.type = e, this.timestamp = performance.now(); } } class De extends Error { constructor(t) { super(), this.type = t; } } class hs { constructor(t, e, n) { y(this, "requestControls"); y(this, "abortController", new AbortController()); y(this, "expectedBytesLength"); y(this, "requestByteRange"); y(this, "onChunkDownloaded"); this.request = t, this.httpConfig = e, this.onChunkDownloaded = n.getEventDispatcher("onChunkDownloaded"); const { byteRange: s } = this.request.segment; s && (this.requestByteRange = { ...s }), t.loadedBytes !== 0 && (this.requestByteRange = this.requestByteRange ?? { start: 0 }, this.requestByteRange.start = this.requestByteRange.start + t.loadedBytes), this.request.totalBytes && (this.expectedBytesLength = this.request.totalBytes - this.request.loadedBytes), this.requestControls = this.request.start({ downloadSource: "http" }, { abort: () => this.abortController.abort("abort"), notReceivingBytesTimeoutMs: this.httpConfig.httpNotReceivingBytesTimeoutMs }), this.fetch(); } async fetch() { var e, n, s, o; const { segment: t } = this.request; try { let h = await ((n = (e = this.httpConfig).httpRequestSetup) == null ? void 0 : n.call(e, t.url, t.byteRange, this.abortController.signal, this.requestByteRange)); if (!h) { const u = new Headers(this.requestByteRange ? { Range: `bytes=${this.requestByteRange.start}-${this.requestByteRange.end ?? ""}` } : void 0); h = new Request(t.url, { headers: u, signal: this.abortController.signal }); } if (this.abortController.signal.aborted) throw new DOMException("Request aborted before request fetch", "AbortError"); const a = await window.fetch(h); if (this.handleResponseHeaders(a), !a.body) return; const { requestControls: g } = this; g.firstBytesReceived(); const S = a.body.getReader(); for await (const u of async function* (f) { for (; ; ) { const { done: b, value: x } = await f.read(); if (b) break; yield x; } }(S)) this.requestControls.addLoadedChunk(u), this.onChunkDownloaded(u.byteLength, "http"); if (!(await ((o = (s = this.httpConfig).validateHTTPSegment) == null ? void 0 : o.call(s, t.url, t.byteRange, this.request.data)) ?? !0)) throw this.request.clearLoadedBytes(), new N("http-segment-validation-failed"); g.completeOnSuccess(); } catch (h) { this.handleError(h); } } handleResponseHeaders(t) { if (!t.ok) throw t.status === 406 ? (this.request.clearLoadedBytes(), new N("http-bytes-mismatch", t.statusText)) : new N("http-error", t.statusText); const { requestByteRange: e } = this; if (e) if (t.status === 200) { if (this.request.segment.byteRange) throw new N("http-unexpected-status-code"); this.request.clearLoadedBytes(); } else { if (t.status !== 206) throw new N("http-unexpected-status-code", t.statusText); const n = t.headers.get("Content-Length"); if (n && this.expectedBytesLength !== void 0 && this.expectedBytesLength !== +n) throw this.request.clearLoadedBytes(), new N("http-bytes-mismatch", t.statusText); const s = t.headers.get("Content-Range"), o = s ? function(h) { const a = ds.exec(h.trim()); if (!a) return; const [, g, S, u] = a; return { from: g ? parseInt(g) : void 0, to: S ? parseInt(S) : void 0, total: u ? parseInt(u) : void 0 }; }(s) : void 0; if (o) { const { from: h, to: a } = o, g = a !== void 0 && h !== void 0 ? a - h + 1 : void 0; if (g !== void 0 && this.expectedBytesLength !== g || h !== void 0 && e.start !== h || a !== void 0 && e.end !== void 0 && e.end !== a) throw this.request.clearLoadedBytes(), new N("http-bytes-mismatch", t.statusText); } } if (t.status === 200 && this.request.totalBytes === void 0) { const n = t.headers.get("Content-Length"); n && this.request.setTotalBytes(+n); } } handleError(t) { if (t instanceof Error) { if (t.name !== "abort") return; const e = t instanceof N ? t : new N("http-error", t.message); this.requestControls.abortOnError(e); } } } const ds = /^bytes (?:(?:(\d+)|)-(?:(\d+)|)|\*)\/(?:(\d+)|\*)$/; function cs(r) { return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r; } var G, Y, vn = { exports: {} }, q = vn.exports = {}; function ae() { throw new Error("setTimeout has not been defined"); } function he() { throw new Error("clearTimeout has not been defined"); } function kn(r) { if (G === setTimeout) return setTimeout(r, 0); if ((G === ae || !G) && setTimeout) return G = setTimeout, setTimeout(r, 0); try { return G(r, 0); } catch { try { return G.call(null, r, 0); } catch { return G.call(this, r, 0); } } } (function() { try { G = typeof setTimeout == "function" ? setTimeout : ae; } catch { G = ae; } try { Y = typeof clearTimeout == "function" ? clearTimeout : he; } catch { Y = he; } })(); var it, J = [], ut = !1, Dt = -1; function us() { ut && it && (ut = !1, it.length ? J = it.concat(J) : Dt = -1, J.length && Tn()); } function Tn() { if (!ut) { var r = kn(us); ut = !0; for (var t = J.length; t; ) { for (it = J, J = []; ++Dt < t; ) it && it[Dt].run(); Dt = -1, t = J.length; } it = null, ut = !1, function(e) { if (Y === clearTimeout) return clearTimeout(e); if ((Y === he || !Y) && clearTimeout) return Y = clearTimeout, clearTimeout(e); try { return Y(e); } catch { try { return Y.call(null, e); } catch { return Y.call(this, e); } } }(r); } } function Ne(r, t) { this.fun = r, this.array = t; } function Q() { } q.nextTick = function(r) { var t = new Array(arguments.length - 1); if (arguments.length > 1) for (var e = 1; e < arguments.length; e++) t[e - 1] = arguments[e]; J.push(new Ne(r, t)), J.length !== 1 || ut || kn(Tn); }, Ne.prototype.run = function() { this.fun.apply(null, this.array); }, q.title = "browser", q.browser = !0, q.env = {}, q.argv = [], q.version = "", q.versions = {}, q.on = Q, q.addListener = Q, q.once = Q, q.off = Q, q.removeListener = Q, q.removeAllListeners = Q, q.emit = Q, q.prependListener = Q, q.prependOnceListener = Q, q.listeners = function(r) { return []; }, q.binding = function(r) { throw new Error("process.binding is not supported"); }, q.cwd = function() { return "/"; }, q.chdir = function(r) { throw new Error("process.chdir is not supported"); }, q.umask = function() { return 0; }; const Nt = cs(vn.exports); var ls = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}; function ot(r) { return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r; } var Me, Fe, Ue, He, $e, Xt = { exports: {} }; function gs() { if (Fe) return Me; Fe = 1; var r = 1e3, t = 60 * r, e = 60 * t, n = 24 * e, s = 7 * n, o = 365.25 * n; function h(a, g, S, u) { var f = g >= 1.5 * S; return Math.round(a / S) + " " + u + (f ? "s" : ""); } return Me = function(a, g) { g = g || {}; var S = typeof a; if (S === "string" && a.length > 0) return function(u) { if (!((u = String(u)).length > 100)) { var f = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(u); if (f) { var b = parseFloat(f[1]); switch ((f[2] || "ms").toLowerCase()) { case "years": case "year": case "yrs": case "yr": case "y": return b * o; case "weeks": case "week": case "w": return b * s; case "days": case "day": case "d": return b * n; case "hours": case "hour": case "hrs": case "hr": case "h": return b * e; case "minutes": case "minute": case "mins": case "min": case "m": return b * t; case "seconds": case "second": case "secs": case "sec": case "s": return b * r; case "milliseconds": case "millisecond": case "msecs": case "msec": case "ms": return b; default: return; } } } }(a); if (S === "number" && isFinite(a)) return g.long ? function(u) { var f = Math.abs(u); return f >= n ? h(u, f, n, "day") : f >= e ? h(u, f, e, "hour") : f >= t ? h(u, f, t, "minute") : f >= r ? h(u, f, r, "second") : u + " ms"; }(a) : function(u) { var f = Math.abs(u); return f >= n ? Math.round(u / n) + "d" : f >= e ? Math.round(u / e) + "h" : f >= t ? Math.round(u / t) + "m" : f >= r ? Math.round(u / r) + "s" : u + "ms"; }(a); throw new Error("val is not a non-empty string or a valid number. val=" + JSON.stringify(a)); }; } var xn = ($e || ($e = 1, function(r, t) { t.formatArgs = function(n) { if (n[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + n[0] + (this.useColors ? "%c " : " ") + "+" + r.exports.humanize(this.diff), !this.useColors) return; const s = "color: " + this.color; n.splice(1, 0, s, "color: inherit"); let o = 0, h = 0; n[0].replace(/%[a-zA-Z%]/g, (a) => { a !== "%%" && (o++, a === "%c" && (h = o)); }), n.splice(h, 0, s); }, t.save = function(n) { try { n ? t.storage.setItem("debug", n) : t.storage.removeItem("debug"); } catch { } }, t.load = function() { let n; try { n = t.storage.getItem("debug"); } catch { } return !n && Nt !== void 0 && "env" in Nt && (n = Nt.env.DEBUG), n; }, t.useColors = function() { if (typeof window < "u" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) return !0; if (typeof navigator < "u" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) return !1; let n; return typeof document < "u" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || typeof window < "u" && window.console && (window.console.firebug || window.console.exception && window.console.table) || typeof navigator < "u" && navigator.userAgent && (n = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(n[1], 10) >= 31 || typeof navigator < "u" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/); }, t.storage = function() { try { return localStorage; } catch { } }(), t.destroy = /* @__PURE__ */ (() => { let n = !1; return () => { n || (n = !0, console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")); }; })(), t.colors = ["#0000CC", "#0000FF", "#0033CC", "#0033FF", "#0066CC", "#0066FF", "#0099CC", "#0099FF", "#00CC00", "#00CC33", "#00CC66", "#00CC99", "#00CCCC", "#00CCFF", "#3300CC", "#3300FF", "#3333CC", "#3333FF", "#3366CC", "#3366FF", "#3399CC", "#3399FF", "#33CC00", "#33CC33", "#33CC66", "#33CC99", "#33CCCC", "#33CCFF", "#6600CC", "#6600FF", "#6633CC", "#6633FF", "#66CC00", "#66CC33", "#9900CC", "#9900FF", "#9933CC", "#9933FF", "#99CC00", "#99CC33", "#CC0000", "#CC0033", "#CC0066", "#CC0099", "#CC00CC", "#CC00FF", "#CC3300", "#CC3333", "#CC3366", "#CC3399", "#CC33CC", "#CC33FF", "#CC6600", "#CC6633", "#CC9900", "#CC9933", "#CCCC00", "#CCCC33", "#FF0000", "#FF0033", "#FF0066", "#FF0099", "#FF00CC", "#FF00FF", "#FF3300", "#FF3333", "#FF3366", "#FF3399", "#FF33CC", "#FF33FF", "#FF6600", "#FF6633", "#FF9900", "#FF9933", "#FFCC00", "#FFCC33"], t.log = console.debug || console.log || (() => { }), r.exports = (He || (He = 1, Ue = function(n) { function s(a) { let g, S, u, f = null; function b(...x) { if (!b.enabled) return; const C = b, d = Number(/* @__PURE__ */ new Date()), l = d - (g || d); C.diff = l, C.prev = g, C.curr = d, g = d, x[0] = s.coerce(x[0]), typeof x[0] != "string" && x.unshift("%O"); let c = 0; x[0] = x[0].replace(/%([a-zA-Z%])/g, (m, p) => { if (m === "%%") return "%"; c++; const _ = s.formatters[p]; if (typeof _ == "function") { const T = x[c]; m = _.call(C, T), x.splice(c, 1), c--; } return m; }), s.formatArgs.call(C, x), (C.log || s.log).apply(C, x); } return b.namespace = a, b.useColors = s.useColors(), b.color = s.selectColor(a), b.extend = o, b.destroy = s.destroy, Object.defineProperty(b, "enabled", { enumerable: !0, configurable: !1, get: () => f !== null ? f : (S !== s.namespaces && (S = s.namespaces, u = s.enabled(a)), u), set: (x) => { f = x; } }), typeof s.init == "function" && s.init(b), b; } function o(a, g) { const S = s(this.namespace + (g === void 0 ? ":" : g) + a); return S.log = this.log, S; } function h(a, g) { let S = 0, u = 0, f = -1, b = 0; for (; S < a.length; ) if (u < g.length && (g[u] === a[S] || g[u] === "*")) g[u] === "*" ? (f = u, b = S, u++) : (S++, u++); else { if (f === -1) return !1; u = f + 1, b++, S = b; } for (; u < g.length && g[u] === "*"; ) u++; return u === g.length; } return s.debug = s, s.default = s, s.coerce = function(a) { return a instanceof Error ? a.stack || a.message : a; }, s.disable = function() { const a = [...s.names, ...s.skips.map((g) => "-" + g)].join(","); return s.enable(""), a; }, s.enable = function(a) { s.save(a), s.namespaces = a, s.names = [], s.skips = []; const g = (typeof a == "string" ? a : "").trim().replace(" ", ",").split(",").filter(Boolean); for (const S of g) S[0] === "-" ? s.skips.push(S.slice(1)) : s.names.push(S); }, s.enabled = function(a) { for (const g of s.skips) if (h(a, g)) return !1; for (const g of s.names) if (h(a, g)) return !0; return !1; }, s.humanize = gs(), s.destroy = function() { console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."); }, Object.keys(n).forEach((a) => { s[a] = n[a]; }), s.names = [], s.skips = [], s.formatters = {}, s.selectColor = function(a) { let g = 0; for (let S = 0; S < a.length; S++) g = (g << 5) - g + a.charCodeAt(S), g |= 0; return s.colors[Math.abs(g) % s.colors.length]; }, s.enable(s.load()), s; }), Ue)(t); const { formatters: e } = r.exports; e.j = function(n) { try { return JSON.stringify(n); } catch (s) { return "[UnexpectedJSONParseError]: " + s.message; } }; }(Xt, Xt.exports)), Xt.exports); const H = ot(xn); var je, Lt = { exports: {} }; function An() { if (je) return Lt.exports; je = 1; var r, t = typeof Reflect == "object" ? Reflect : null, e = t && typeof t.apply == "function" ? t.apply : function(d, l, c) { return Function.prototype.apply.call(d, l, c); }; r = t && typeof t.ownKeys == "function" ? t.ownKeys : Object.getOwnPropertySymbols ? function(d) { return Object.getOwnPropertyNames(d).concat(Object.getOwnPropertySymbols(d)); } : function(d) { return Object.getOwnPropertyNames(d); }; var n = Number.isNaN || function(d) { return d != d; }; function s() { s.init.call(this); } Lt.exports = s, Lt.exports.once = function(d, l) { return new Promise(function(c, m) { function p(T) { d.removeListener(l, _), m(T); } function _() { typeof d.removeListener == "function" && d.removeListener("error", p), c([].slice.call(arguments)); } C(d, l, _, { once: !0 }), l !== "error" && function(T, I, B) { typeof T.on == "function" && C(T, "error", I, B); }(d, p, { once: !0 }); }); }, s.EventEmitter = s, s.prototype._events = void 0, s.prototype._eventsCount = 0, s.prototype._maxListeners = void 0; var o = 10; function h(d) { if (typeof d != "function") throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof d); } function a(d) { return d._maxListeners === void 0 ? s.defaultMaxListeners : d._maxListeners; } function g(d, l, c, m) { var p, _, T, I; if (h(c), (_ = d._events) === void 0 ? (_ = d._events = /* @__PURE__ */ Object.create(null), d._eventsCount = 0) : (_.newListener !== void 0 && (d.emit("newListener", l, c.listener ? c.listener : c), _ = d._events), T = _[l]), T === void 0) T = _[l] = c, ++d._eventsCount; else if (typeof T == "function" ? T = _[l] = m ? [c, T] : [T, c] : m ? T.unshift(c) : T.push(c), (p = a(d)) > 0 && T.length > p && !T.warned) { T.warned = !0; var B = new Error("Possible EventEmitter memory leak detected. " + T.length + " " + String(l) + " listeners added. Use emitter.setMaxListeners() to increase limit"); B.name = "MaxListenersExceededWarning", B.emitter = d, B.type = l, B.count = T.length, I = B, console && console.warn && console.warn(I); } return d; } function S() { if (!this.fired) return this.target.removeListener(this.type, this.wrapFn), this.fired = !0, arguments.length === 0 ? this.listener.call(this.target) : this.listener.apply(this.target, arguments); } function u(d, l, c) { var m = { fired: !1, wrapFn: void 0, target: d, type: l, listener: c }, p = S.bind(m); return p.listener = c, m.wrapFn = p, p; } function f(d, l, c) { var m = d._events; if (m === void 0) return []; var p = m[l]; return p === void 0 ? [] : typeof p == "function" ? c ? [p.listener || p] : [p] : c ? function(_) { for (var T = new Array(_.length), I = 0; I < T.length; ++I) T[I] = _[I].listener || _[I]; return T; }(p) : x(p, p.length); } function b(d) { var l = this._events; if (l !== void 0) { var c = l[d]; if (typeof c == "function") return 1; if (c !== void 0) return c.length; } return 0; } function x(d, l) { for (var c = new Array(l), m = 0; m < l; ++m) c[m] = d[m]; return c; } function C(d, l, c, m) { if (typeof d.on == "function") m.once ? d.once(l, c) : d.on(l, c); else { if (typeof d.addEventListener != "function") throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof d); d.addEventListener(l, function p(_) { m.once && d.removeEventListener(l, p), c(_); }); } } return Object.defineProperty(s, "defaultMaxListeners", { enumerable: !0, get: function() { return o; }, set: function(d) { if (typeof d != "number" || d < 0 || n(d)) throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + d + "."); o = d; } }), s.init = function() { this._events !== void 0 && this._events !== Object.getPrototypeOf(this)._events || (this._events = /* @__PURE__ */ Object.create(null), this._eventsCount = 0), this._maxListeners = this._maxListeners || void 0; }, s.prototype.setMaxListeners = function(d) { if (typeof d != "number" || d < 0 || n(d)) throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + d + "."); return this._maxListeners = d, this; }, s.prototype.getMaxListeners = function() { return a(this); }, s.prototype.emit = function(d) { for (var l = [], c = 1; c < arguments.length; c++) l.push(arguments[c]); var m = d === "error", p = this._events; if (p !== void 0) m = m && p.error === void 0; else if (!m) return !1; if (m) { var _; if (l.length > 0 && (_ = l[0]), _ instanceof Error) throw _; var T = new Error("Unhandled error." + (_ ? " (" + _.message + ")" : "")); throw T.context = _, T; } var I = p[d]; if (I === void 0) return !1; if (typeof I == "function") e(I, this, l); else { var B = I.length, at = x(I, B); for (c = 0; c < B; ++c) e(at[c], this, l); } return !0; }, s.prototype.addListener = function(d, l) { return g(this, d, l, !1); }, s.prototype.on = s.prototype.addListener, s.prototype.prependListener = function(d, l) { return g(this, d, l, !0); }, s.prototype.once = function(d, l) { return h(l), this.on(d, u(this, d, l)), this; }, s.prototype.prependOnceListener = function(d, l) { return h(l), this.prependListener(d, u(this, d, l)), this; }, s.prototype.removeListener = function(d, l) { var c, m, p, _, T; if (h(l), (m = this._events) === void 0) return this; if ((c = m[d]) === void 0) return this; if (c === l || c.listener === l) --this._eventsCount == 0 ? this._events = /* @__PURE__ */ Object.create(null) : (delete m[d], m.removeListener && this.emit("removeListener", d, c.listener || l)); else if (typeof c != "function") { for (p = -1, _ = c.length - 1; _ >= 0; _--) if (c[_] === l || c[_].listener === l) { T = c[_].listener, p = _; break; } if (p < 0) return this; p === 0 ? c.shift() : function(I, B) { for (; B + 1 < I.length; B++) I[B] = I[B + 1]; I.pop(); }(c, p), c.length === 1 && (m[d] = c[0]), m.removeListener !== void 0 && this.emit("removeListener", d, T || l); } return this; }, s.prototype.off = s.prototype.removeListener, s.prototype.removeAllListeners = function(d) { var l, c, m; if ((c = this._events) === void 0) return this; if (c.removeListener === void 0) return arguments.length === 0 ? (this._events = /* @__PURE__ */ Object.create(null), this._eventsCount = 0) : c[d] !== void 0 && (--this._eventsCount == 0 ? this._events = /* @__PURE__ */ Object.create(null) : delete c[d]), this; if (arguments.length === 0) { var p, _ = Object.keys(c); for (m = 0; m < _.length; ++m) (p = _[m]) !== "removeListener" && this.removeAllListeners(p); return this.removeAllListeners("removeListener"), this._events = /* @__PURE__ */ Object.create(null), this._eventsCount = 0, this; } if (typeof (l = c[d]) == "function") this.removeListener(d, l); else if (l !== void 0) for (m = l.length - 1; m >= 0; m--) this.removeListener(d, l[m]); return this; }, s.prototype.listeners = function(d) { return f(this, d, !0); }, s.prototype.rawListeners = function(d) { return f(this, d, !1); }, s.listenerCount = function(d, l) { return typeof d.listenerCount == "function" ? d.listenerCount(l) : b.call(d, l); }, s.prototype.listenerCount = b, s.prototype.eventNames = function() { return this._eventsCount > 0 ? r(this._events) : []; }, Lt.exports; } const Ln = ot(An()); var We, Qe, ze, It = { exports: {} }, ms = function() { if (ze) return It.exports; ze = 1; var r = (Qe || (Qe = 1, We = function n(s, o) { if (s && o) return n(s)(o); if (typeof s != "function") throw new TypeError("need wrapper function"); return Object.keys(s).forEach(function(a) { h[a] = s[a]; }), h; function h() { for (var a = new Array(arguments.length), g = 0; g < a.length; g++) a[g] = arguments[g]; var S = s.apply(this, a), u = a[a.length - 1]; return typeof S == "function" && S !== u && Object.keys(u).forEach(function(f) { S[f] = u[f]; }), S; } }), We); function t(n) { var s = function() { return s.called ? s.value : (s.called = !0, s.value = n.apply(this, arguments)); }; return s.called = !1, s; } function e(n) { var s = function() { if (s.called) throw new Error(s.onceError); return s.called = !0, s.value = n.apply(this, arguments); }, o = n.name || "Function wrapped with `once`"; return s.onceError = o + " shouldn't be called more than once", s.called = !1, s; } return It.exports = r(t), It.exports.strict = r(e), t.proto = t(function() { Object.defineProperty(Function.prototype, "once", { value: function() { return t(this); }, configurable: !0 }), Object.defineProperty(Function.prototype, "onceStrict", { value: function() { return e(this); }, configurable: !0 }); }), It.exports; }(); const ps = ot(ms); var Ge, Ye, te, Je; function In() { if (Ye) return Ge; let r; return Ye = 1, Ge = typeof queueMicrotask == "function" ? queueMicrotask.bind(typeof window < "u" ? window : ls) : (t) => (r || (r = Promise.resolve())).then(t).catch((e) => setTimeout(() => { throw e; }, 0)); } var fs = function() { if (Je) return te; Je = 1, te = function(t, e) { let n, s, o, h = !0; Array.isArray(t) ? (n = [], s = t.length) : (o = Object.keys(t), n = {}, s = o.length); function a(S) { function u() { e && e(S, n), e = null; } h ? r(u) : u(); } function g(S, u, f) { n[S] = f, (--s == 0 || u) && a(u); } s ? o ? o.forEach(function(S) { t[S](function(u, f) { g(S, u, f); }); }) : t.forEach(function(S, u) { S(function(f, b) { g(u, f, b); }); }) : a(null), h = !1; }; const r = In(); return te; }(); const _s = ot(fs), K = typeof window < "u" ? window : self, de = K.RTCPeerConnection || K.mozRTCPeerConnection || K.webkitRTCPeerConnection, ys = K.RTCSessionDescription || K.mozRTCSessionDescription || K.webkitRTCSessionDescription, Ss = K.RTCIceCandidate || K.mozRTCIceCandidate || K.webkitRTCIceCandidate; var Ve, Ke, Ze, Xe, tn, en, nn, sn, rn, on; function ws() { if (Xe) return Ze; Xe = 1; const r = Ke ? Ve : (Ke = 1, Ve = class { constructor(t) { if (!(t > 0) || t - 1 & t) throw new Error("Max size for a FixedFIFO should be a power of two"); this.buffer = new Array(t), this.mask = t - 1, this.top = 0, this.btm = 0, this.next = null; } clear() { this.top = this.btm = 0, this.next = null, this.buffer.fill(void 0); } push(t) { return this.buffer[this.top] === void 0 && (this.buffer[this.top] = t, this.top = this.top + 1 & this.mask, !0); } shift() { const t = this.buffer[this.btm]; if (t !== void 0) return this.buffer[this.btm] = void 0, this.btm = this.btm + 1 & this.mask, t; } peek() { return this.buffer[this.btm]; } isEmpty() { return this.buffer[this.btm] === void 0; } }); return Ze = class { constructor(t) { this.hwm = t || 16, this.head = new r(this.hwm), this.tail = this.head, this.length = 0; } clear() { this.head = this.tail, this.head.clear(), this.length = 0; } push(t) { if (this.length++, !this.head.push(t)) { const e = this.head; this.head = e.next = new r(2 * this.head.buffer.length), this.head.push(t); } } shift() { this.length !== 0 && this.length--; const t = this.tail.shift(); if (t === void 0 && this.tail.next) { const e = this.tail.next; return this.tail.next = null, this.tail = e, this.tail.shift(); } return t; } peek() { const t = this.tail.peek(); return t === void 0 && this.tail.next ? this.tail.next.peek() : t; } isEmpty() { return this.length === 0; } }; } function an() { return en ? tn : (en = 1, tn = class { constructor(r) { this.decoder = new TextDecoder(r === "utf16le" ? "utf16-le" : r); } get remaining() { return -1; } decode(r) { return this.decoder.decode(r, { stream: !0 }); } flush() { return this.decoder.decode(new Uint8Array(0)); } }); } function bs() { if (sn) return nn; sn = 1; const r = an(), t = an(); return nn = class { constructor(e = "utf8") { switch (this.encoding = function(n) { switch (n = n.toLowerCase()) { case "utf8": case "utf-8": return "utf8"; case "ucs2": case "ucs-2": case "utf16le": case "utf-16le": return "utf16le"; case "latin1": case "binary": return "latin1"; case "base64": case "ascii": case "hex": return n; default: throw new Error("Unknown encoding: " + n); } }(e), this.encoding) { case "utf8": this.decoder = new t(); break; case "utf16le": case "base64": throw new Error("Unsupported encoding: " + this.encoding); default: this.decoder = new r(this.encoding); } } get remaining() { return this.decoder.remaining; } push(e) { return typeof e == "string" ? e : this.decoder.decode(e); } write(e) { return this.push(e); } end(e) { let n = ""; return e && (n = this.push(e)), n += this.decoder.flush(), n; } }; } var hn, dn, En = function() { if (on) return rn; on = 1; const { EventEmitter: r } = An(), t = new Error("Stream was destroyed"), e = new Error("Premature close"), n = ws(), s = bs(), o = 536870911, h = 1 ^ o, a = 2 ^ o, g = 32, S = 64, u = 128, f = 256, b = 1024, x = 2048, C = 4096, d = 8192, l = 16384, c = 32768, m = 131072, p = 131328, _ = 16 ^ o, T = 536805375, I = 768 ^ o, B = 536838143, at = 536739839, zt = 1 << 18, $ = 2 << 18, j = 4 << 18, F = 8 << 18, ht = 16 << 18, Z = 32 << 18, W = 64 << 18, pt = 128 << 18, Hn = 256 << 18, we = 512 << 18, be = 1024 << 18, $n = 535822335, Ce = 503316479, ve = 268435455, xt = 262160, jn = 536608751, ke = 8404992, ft = 14, Wn = 15, Te = 8405006, Gt = 33587200, xe = 33587215, Qn = 2359296, Ae = 270794767, At = Symbol.asyncIterator || Symbol("asyncIterator"); class Le { constructor(i, { highWaterMark: w = 16384, map: k = null, mapWritable: A, byteLength: L, byteLengthWritable: E } = {}) { this.stream = i, this.queue = new n(), this.highWaterMark = w, this.buffered = 0, this.error = null, this.pipeline = null, this.drains = null, this.byteLength = E || L || Be, this.map = A || k, this.afterWrite = Kn.bind(this), this.afterUpdateNextTick = ts.bind(this); } get ended() { return !!(this.stream._duplexState & Z); } push(i) { return !(142606350 & this.stream._duplexState) && (this.map !== null && (i = this.map(i)), this.buffered += this.byteLength(i), this.queue.push(i), this.buffered < this.highWaterMark ? (this.stream._duplexState |= F, !0) : (this.stream._duplexState |= 6291456, !1)); } shift() { const i = this.queue.shift(); return this.buffered -= this.byteLength(i), this.buffered === 0 && (this.stream._duplexState &= 534773759), i; } end(i) { typeof i == "function" ? this.stream.once("finish", i) : i != null && this.push(i), this.stream._duplexState = (this.stream._duplexState | we) & $n; } autoBatch(i, w) { const k = [], A = this.stream; for (k.push(i); (A._duplexState & Ae) === Qn; ) k.push(A._writableState.shift()); if (A._duplexState & Wn) return w(null); A._writev(k, w); } update() { const i = this.stream; i._duplexState |= $; do { for (; (i._duplexState & Ae) === F; ) { const w = this.shift(); i._duplexState |= 67371008, i._write(w, this.afterWrite); } 1310720 & i._duplexState || this.updateNonPrimary(); } while (this.continueUpdate() === !0); i._duplexState &= 536346623; } updateNonPrimary() { const i = this.stream; if ((144965647 & i._duplexState) === we) return i._duplexState = i._duplexState | zt, void i._final(Vn.bind(this)); (i._duplexState & ft) != 4 ? (i._duplexState & xe) == 1 && (i._duplexState = (i._duplexState | xt) & h, i._open(Ee.bind(this))) : i._duplexState & Gt || (i._duplexState |= xt, i._destroy(Ie.bind(this))); } continueUpdate() { return !!(this.stream._duplexState & pt) && (this.stream._duplexState &= Ce, !0); } updateCallback() { (35127311 & this.stream._duplexState) === j ? this.update() : this.updateNextTick(); } updateNextTick() { this.stream._duplexState & pt || (this.stream._duplexState |= pt, this.stream._duplexState & $ || queueMicrotask(this.afterUpdateNextTick)); } } class zn { constructor(i, { highWaterMark: w = 16384, map: k = null, mapReadable: A, byteLength: L, byteLengthReadable: E } = {}) { this.stream = i, this.queue = new n(), this.highWaterMark = w === 0 ? 1 : w, this.buffered = 0, this.readAhead = w > 0, this.error = null, this.pipeline = null, this.byteLength = E || L || Be, this.map = A || k, this.pipeTo = null, this.afterRead = Zn.bind(this), this.afterUpdateNextTick = Xn.bind(this); } get ended() { return !!(this.stream._duplexState & l); } pipe(i, w) { if (this.pipeTo !== null) throw new Error("Can only pipe to one destination"); if (typeof w != "function" && (w = null), this.stream._duplexState |= 512, this.pipeTo = i, this.pipeline = new Yn(this.stream, i, w), w && this.stream.on("error", Oe), yt(i)) i._writableState.pipeline = this.pipeline, w && i.on("error", Oe), i.on("finish", this.pipeline.finished.bind(this.pipeline)); else { const k = this.pipeline.done.bind(this.pipeline, i), A = this.pipeline.done.bind(this.pipeline, i, null); i.on("error", k), i.on("close", A), i.on("finish", this.pipeline.finished.bind(this.pipeline)); } i.on("drain", Jn.bind(this)), this.stream.emit("piping", i), i.emit("pipe", this.stream); } push(i) { const w = this.stream; return i === null ? (this.highWaterMark = 0, w._duplexState = 536805311 & w._duplexState | 1024, !1) : this.map !== null && (i = this.map(i)) === null ? (w._duplexState &= T, this.buffered < this.highWaterMark) : (this.buffered += this.byteLength(i), this.queue.push(i), w._duplexState = (w._duplexState | u) & T, this.buffered < this.highWaterMark); } shift() { const i = this.queue.shift(); return this.buffered -= this.byteLength(i), this.buffered === 0 && (this.stream._duplexState &= 536862591), i; } unshift(i) { const w = [this.map !== null ? this.map(i) : i]; for (; this.buffered > 0; ) w.push(this.shift()); for (let k = 0; k < w.length - 1; k++) { const A = w[k]; this.buffered += this.byteLength(A), this.queue.push(A); } this.push(w[w.length - 1]); } read() { const i = this.stream; if ((16527 & i._duplexState) === u) { const w = this.shift(); return this.pipeTo !== null && this.pipeTo.write(w) === !1 && (i._duplexState &= I), i._duplexState & x && i.emit("data", w), w; } return this.readAhead === !1 && (i._duplexState |= m, this.updateNextTick()), null; } drain() { const i = this.stream; for (; (16527 & i._duplexState) === u && 768 & i._duplexState; ) { const w = this.shift(); this.pipeTo !== null && this.pipeTo.write(w) === !1 && (i._duplexState &= I), i._duplexState & x && i.emit("data", w); } } update() { const i = this.stream; i._duplexState |= g; do { for (this.drain(); this.buffered < this.highWaterMark && (214047 & i._duplexState) === m; ) i._duplexState |= 65552, i._read(this.afterRead), this.drain(); (12431 & i._duplexState) == 4224 && (i._duplexState |= d, i.emit("readable")), 80 & i._duplexState || this.updateNonPrimary(); } while (this.continueUpdate() === !0); i._duplexState &= 536870879; } updateNonPrimary() { const i = this.stream; (1167 & i._duplexState) === b && (i._duplexState = 536869887 & i._duplexState | 16384, i.emit("end"), (i._duplexState & Te) === ke && (i._duplexState |= 4), this.pipeTo !== null && this.pipeTo.end()), (i._duplexState & ft) != 4 ? (i._duplexState & xe) == 1 && (i._duplexState = (i._duplexState | xt) & h, i._open(Ee.bind(this))) : i._duplexState & Gt || (i._duplexState |= xt, i._destroy(Ie.bind(this))); } continueUpdate() { return !!(this.stream._duplexState & c) && (this.stream._duplexState &= B, !0); } updateCallback() { (32879 & this.stream._duplexState) === S ? this.update() : this.updateNextTick(); } updateNextTickIfOpen() { 32769 & this.stream._duplexState || (this.stream._duplexState |= c, this.stream._duplexState & g || queueMicrotask(this.afterUpdateNextTick)); } updateNextTick() { this.stream._duplexState & c || (this.stream._duplexState |= c, this.stream._duplexState & g || queueMicrotask(this.afterUpdateNextTick)); } } class Gn { constructor(i) { this.data = null, this.afterTransform = es.bind(i), this.afterFinal = null; } } class Yn { constructor(i, w, k) { this.from = i, this.to = w, this.afterPipe = k, this.error = null, this.pipeToFinished = !1; } finished() { this.pipeToFinished = !0; } done(i, w) { w && (this.error = w), i !== this.to || (this.to = null, this.from === null) ? i !== this.from || (this.from = null, this.to === null) ? (this.afterPipe !== null && this.afterPipe(this.error), this.to = this.from = this.afterPipe = null) : i._duplexState & l || this.to.destroy(this.error || new Error("Readable stream closed before ending")) : this.from._duplexState & l && this.pipeToFinished || this.from.destroy(this.error || new Error("Writable stream closed prematurely")); } } function Jn() { this.stream._duplexState |= 512, this.updateCallback(); } function Vn(v) { const i = this.stream; v && i.destroy(v), i._duplexState & ft || (i._duplexState |= Z, i.emit("finish")), (i._duplexState & Te) === ke && (i._duplexState |= 4), i._duplexState &= 402391039, i._duplexState & $ ? this.updateNextTick() : this.update(); } function Ie(v) { const i = this.stream; v || this.error === t || (v = this.error), v && i.emit("error", v), i._duplexState |= 8, i.emit("close"); const w = i._readableState, k = i._writableState; if (w !== null && w.pipeline !== null && w.pipeline.done(i, v), k !== null) { for (; k.drains !== null && k.drains.length > 0; ) k.drains.shift().resolve(!1); k.pipeline !== null && k.pipeline.done(i, v); } } function Kn(v) { const i = this.stream; v && i.destroy(v), i._duplexState &= 469499903, this.drains !== null && function(w) { for (let k = 0; k < w.length; k++) --w[k].writes == 0 && (w.shift().resolve(!0), k--); }(this.drains), (6553615 & i._duplexState) === ht && (i._duplexState &= 532676607, (i._duplexState & W) === W && i.emit("drain")), this.updateCallback(); } function Zn(v) { v && this.stream.destroy(v), this.stream._duplexState &= _, this.readAhead !== !1 || this.stream._duplexState & f || (this.stream._duplexState &= at), this.updateCallback(); } function Xn() { this.stream._duplexState & g || (this.stream._duplexState &= B, this.update()); } function ts() { this.stream._duplexState & $ || (this.stream._duplexState &= Ce, this.update()); } function Ee(v) { const i = this.stream; v && i.destroy(v), 4 & i._duplexState || (17423 & i._duplexState || (i._duplexState |= S), 142606351 & i._duplexState || (i._duplexState |= j), i.emit("open")), i._duplexState &= jn, i._writableState !== null && i._writableState.updateCallback(), i._readableState !== null && i._readableState.updateCallback(); } function es(v, i) { i != null && this.push(i), this._writableState.afterWrite(v); } function ns(v) { this._readableState !== null && (v === "data" && (this._duplexState |= 133376, this._readableState.updateNextTick()), v === "readable" && (this._duplexState |= C, this._readableState.updateNextTick())), this._writableState !== null && v === "drain" && (this._duplexState |= W, this._writableState.updateNextTick()); } class Yt extends r { constructor(i) { super(), this._duplexState = 0, this._readableState = null, this._writableState = null, i && (i.open && (this._open = i.open), i.destroy && (this._destroy = i.destroy), i.predestroy && (this._predestroy = i.predestroy), i.signal && i.signal.addEventListener("abort", is.bind(this))), this.on("newListener", ns); } _open(i) { i(null); } _destroy(i) { i(null); } _predestroy() { } get readable() { return this._readableState !== null || void 0; } get writable() { return this._writableState !== null || void 0; } get destroyed() { return !!(8 & this._duplexState); } get destroying() { return !!(this._duplexState & ft); } destroy(i) { this._duplexState & ft || (i || (i = t), this._duplexState = 535822271 & this._duplexState | 4, this._readableState !== null && (this._readableState.highWaterMark = 0, this._readableState.error = i), this._writableState !== null && (this._writableState.highWaterMark = 0, this._writableState.error = i), this._duplexState |= 2, this._predestroy(), this._duplexState &= a, this._readableState !== null && this._readableState.updateNextTick(), this._writableState !== null && this._writableState.updateNextTick()); } } class _t extends Yt { constructor(i) { super(i), this._duplexState |= 8519681, this._readableState = new zn(this, i), i && (this._readableState.readAhead === !1 && (this._duplexState &= at), i.read && (this._read = i.read), i.eagerOpen && this._readableState.updateNextTick(), i.encoding && this.setEncoding(i.encoding)); } setEncoding(i) { const w = new s(i), k = this._readableState.map || rs; return this._readableState.map = function(A) { const L = w.push(A); return L === "" && (A.byteLength !== 0 || w.remaining > 0) ? null : k(L); }, this; } _read(i) { i(null); } pipe(i, w) { return this._readableState.updateNextTick(), this._readableState.pipe(i, w), i; } read() { return this._readableState.updateNextTick(), this._readableState.read(); } push(i) { return this._readableState.updateNextTickIfOpen(), this._readableState.push(i); } unshift(i) { return this._readableState.updateNextTickIfOpen(), this._readableState.unshift(i); } resume() { return this._duplexState |= p, this._readableState.updateNextTick(), this; } pause() { return this._duplexState &= this._readableState.readAhead === !1 ? 536739583 : 536870655, this; } static _fromAsyncIterator(i, w) { let k; const A = new _t({ ...w, read(E) { i.next().then(L).then(E.bind(null, null)).catch(E); }, predestroy() { k = i.return(); }, destroy(E) { if (!k) return E(null); k.then(E.bind(null, null)).catch(E); } }); return A; function L(E) { E.done ? A.push(null) : A.push(E.value); } } static from(i, w) { if (yt(k = i) && k.readable) return i; var k; if (i[At]) return this._fromAsyncIterator(i[At](), w); Array.isArray(i) || (i = i === void 0 ? [] : [i]); let A = 0; return new _t({ ...w, read(L) { this.push(A === i.length ? null : i[A++]), L(null); } }); } static isBackpressured(i) { return !!(17422 & i._duplexState) || i._readableState.buffered >= i._readableState.highWaterMark; } static isPaused(i) { return !(i._duplexState & f); } [At]() { const i = this; let w = null, k = null, A = null; return this.on("error", (O) => { w = O; }), this.on("readable", function() { k !== null && L(i.read()); }), this.on("close", function() { k !== null && L(null); }), { [At]() { return this; }, next: () => new Promise(function(O, st) { k = O, A = st; const R = i.read(); R !== null ? L(R) : 8 & i._duplexState && L(null); }), return: () => E(null), throw: (O) => E(O) }; function L(O) { A !== null && (w ? A(w) : O !== null || i._duplexState & l ? k({ value: O, done: O === null }) : A(t), A = k = null); } function E(O) { return i.destroy(O), new Promise((st, R) => { if (8 & i._duplexState) return st({ value: void 0, done: !0 }); i.once("close", function() { O ? R(O) : st({ value: void 0, done: !0 }); }); }); } } } class Jt extends Yt { constructor(i) { super(i), this._duplexState |= 16385, this._writableState = new Le(this, i), i && (i.writev && (this._writev = i.writev), i.write && (this._write = i.write), i.final && (this._final = i.final), i.eagerOpen && this._writableState.updateNextTick()); } cork() { this._duplexState |= be; } uncork() { this._duplexState &= ve, this._writableState.updateNextTick(); } _writev(i, w) { w(null); } _write(i, w) { this._writableState.autoBatch(i, w); } _final(i) { i(null); } static isBackpressured(i) { return !!(146800654 & i._duplexState); } static drained(i) { if (i.destroyed) return Promise.resolve(!1); const w = i._writableState; var k; const A = ((k = i)._writev !== Jt.prototype._writev && k._writev !== Vt.prototype._writev ? Math.min(1, w.queue.length) : w.queue.length) + (i._duplexState & Hn ? 1 : 0); return A === 0 ? Promise.resolve(!0) : (w.drains === null && (w.drains = []), new Promise((L) => { w.drains.push({ writes: A, resolve: L }); })); } write(i) { return this._writableState.updateNextTick(), this._writableState.push(i); } end(i) { return this._writableState.updateNextTick(), this._writableState.end(i), this; } } class Vt extends _t { constructor(i) { super(i), this._duplexState = 1 | this._duplexState & m, this._writableState = new Le(this, i), i && (i.writev && (this._writev = i.writev), i.write && (this._write = i.write), i.final && (this._final = i.final)); } cork() { this._duplexState |= be; } uncork() { this._duplexState &= ve, this._writableState.updateNextTick(); } _writev(i, w) { w(null); } _write(i, w) { this._writableState.autoBatch(i, w); } _final(i) { i(null); } write(i) { return this._writableState.updateNextTick(), this._writableState.push(i); } end(i) { return this._writableState.updateNextTick(), this._writableState.end(i), this; } } class Re extends Vt { constructor(i) { super(i), this._transformState = new Gn(this), i && (i.transform && (this._transform = i.transform), i.flush && (this._flush = i.flush)); } _write(i, w) { this._readableState.buffered >= this._readableState.highWaterMark ? this._transformState.data = i : this._transform(i, this._transformState.afterTransform); } _read(i) { if (this._transformState.data !== null) { const w = this._transformState.data; this._transformState.data = null, i(null), this._transform(w, this._transformState.afterTransform); } else i(null); } destroy(i) { super.destroy(i), this._transformState.data !== null && (this._transformState.data = null, this._transformState.afterTransform()); } _transform(i, w) { w(null, i); } _flush(i) { i(null); } _final(i) { this._transformState.afterFinal = i, this._flush(ss.bind(this)); } } function ss(v, i) { const w = this._transformState.afterFinal; if (v) return w(v); i != null && this.push(i), this.push(null), w(null); } function Pe(v, ...i) { const w = Array.isArray(v) ? [...v, ...i] : [v, ...i], k = w.length && typeof w[w.length - 1] == "function" ? w.pop() : null; if (w.length < 2) throw new Error("Pipeline requires at least 2 streams"); let A = w[0], L = null, E = null; for (let R = 1; R < w.length; R++) L = w[R], yt(A) ? A.pipe(L, st) : (O(A, !0, R > 1, st), A.pipe(L)), A = L; if (k) { let R = !1; const St = yt(L) || !(!L._writableState || !L._writableState.autoDestroy); L.on("error", (Kt) => { E === null && (E = Kt); }), L.on("finish", () => { R = !0, St || k(E); }), St && L.on("close", () => k(E || (R ? null : e))); } return L; function O(R, St, Kt, Zt) { R.on("error", Zt), R.on("close", function() { if (R._readableState && !R._readableState.ended || Kt && R._writableState && !R._writableState.ended) return Zt(e); }); } function st(R) { if (R && !E) { E = R; for (const St of w) St.destroy(R); } } } function rs(v) { return v; } function qe(v) { return !!v._readableState || !!v._writableState; } function yt(v) { return typeof v._duplexState == "number" && qe(v); } function Be(v) { return function(i) { return typeof i == "object" && i !== null && typeof i.byteLength == "number"; }(v) ? v.byteLength : 1024; } function Oe() { } function is() { this.destroy(new Error("Stream aborted.")); } return rn = { pipeline: Pe, pipelinePromise: function(...v) { return new Promise((i, w) => Pe(...v, (k) => { if (k) return w(k); i