UNPKG

@millicast/sdk

Version:

SDK for building a realtime broadcaster using the Millicast platform.

1,070 lines 440 kB
var Os = Object.defineProperty, Ns = Object.defineProperties; var _s = Object.getOwnPropertyDescriptors; var Rt = Object.getOwnPropertySymbols; var Gn = Object.prototype.hasOwnProperty, Hn = Object.prototype.propertyIsEnumerable; var qn = (n, e, t) => e in n ? Os(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t, ie = (n, e) => { for (var t in e || (e = {})) Gn.call(e, t) && qn(n, t, e[t]); if (Rt) for (var t of Rt(e)) Hn.call(e, t) && qn(n, t, e[t]); return n; }, Be = (n, e) => Ns(n, _s(e)); var at = (n, e) => { var t = {}; for (var r in n) Gn.call(n, r) && e.indexOf(r) < 0 && (t[r] = n[r]); if (n != null && Rt) for (var r of Rt(n)) e.indexOf(r) < 0 && Hn.call(n, r) && (t[r] = n[r]); return t; }; var Wn = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}; function Ct(n) { return n && n.__esModule && Object.prototype.hasOwnProperty.call(n, "default") ? n.default : n; } var Gt = { exports: {} }; /*! * js-logger - http://github.com/jonnyreeves/js-logger * Jonny Reeves, http://jonnyreeves.co.uk/ * js-logger may be freely distributed under the MIT license. */ var Vs = Gt.exports, $n; function js() { return $n || ($n = 1, function(n) { (function(e) { var t = {}; t.VERSION = "1.6.1"; var r, i = {}, o = function(l, w) { return function() { return w.apply(l, arguments); }; }, c = function() { var l = arguments, w = l[0], g, p; for (p = 1; p < l.length; p++) for (g in l[p]) !(g in w) && l[p].hasOwnProperty(g) && (w[g] = l[p][g]); return w; }, a = function(l, w) { return { value: l, name: w }; }; t.TRACE = a(1, "TRACE"), t.DEBUG = a(2, "DEBUG"), t.INFO = a(3, "INFO"), t.TIME = a(4, "TIME"), t.WARN = a(5, "WARN"), t.ERROR = a(8, "ERROR"), t.OFF = a(99, "OFF"); var f = function(l) { this.context = l, this.setLevel(l.filterLevel), this.log = this.info; }; f.prototype = { // Changes the current logging level for the logging instance. setLevel: function(l) { l && "value" in l && (this.context.filterLevel = l); }, // Gets the current logging level for the logging instance getLevel: function() { return this.context.filterLevel; }, // Is the logger configured to output messages at the supplied level? enabledFor: function(l) { var w = this.context.filterLevel; return l.value >= w.value; }, trace: function() { this.invoke(t.TRACE, arguments); }, debug: function() { this.invoke(t.DEBUG, arguments); }, info: function() { this.invoke(t.INFO, arguments); }, warn: function() { this.invoke(t.WARN, arguments); }, error: function() { this.invoke(t.ERROR, arguments); }, time: function(l) { typeof l == "string" && l.length > 0 && this.invoke(t.TIME, [l, "start"]); }, timeEnd: function(l) { typeof l == "string" && l.length > 0 && this.invoke(t.TIME, [l, "end"]); }, // Invokes the logger callback if it's not being filtered. invoke: function(l, w) { r && this.enabledFor(l) && r(w, c({ level: l }, this.context)); } }; var d = new f({ filterLevel: t.OFF }); (function() { var l = t; l.enabledFor = o(d, d.enabledFor), l.trace = o(d, d.trace), l.debug = o(d, d.debug), l.time = o(d, d.time), l.timeEnd = o(d, d.timeEnd), l.info = o(d, d.info), l.warn = o(d, d.warn), l.error = o(d, d.error), l.log = l.info; })(), t.setHandler = function(l) { r = l; }, t.setLevel = function(l) { d.setLevel(l); for (var w in i) i.hasOwnProperty(w) && i[w].setLevel(l); }, t.getLevel = function() { return d.getLevel(); }, t.get = function(l) { return i[l] || (i[l] = new f(c({ name: l }, d.context))); }, t.createDefaultHandler = function(l) { l = l || {}, l.formatter = l.formatter || function(m, I) { I.name && m.unshift("[" + I.name + "]"); }; var w = {}, g = function(p, m) { Function.prototype.apply.call(p, console, m); }; return typeof console > "u" ? function() { } : function(p, m) { p = Array.prototype.slice.call(p); var I = console.log, R; m.level === t.TIME ? (R = (m.name ? "[" + m.name + "] " : "") + p[0], p[1] === "start" ? console.time ? console.time(R) : w[R] = (/* @__PURE__ */ new Date()).getTime() : console.timeEnd ? console.timeEnd(R) : g(I, [R + ": " + ((/* @__PURE__ */ new Date()).getTime() - w[R]) + "ms"])) : (m.level === t.WARN && console.warn ? I = console.warn : m.level === t.ERROR && console.error ? I = console.error : m.level === t.INFO && console.info ? I = console.info : m.level === t.DEBUG && console.debug ? I = console.debug : m.level === t.TRACE && console.trace && (I = console.trace), l.formatter(p, m), g(I, p)); }; }, t.useDefaults = function(l) { t.setLevel(l && l.defaultLevel || t.DEBUG), t.setHandler(t.createDefaultHandler(l)); }, t.setDefaults = t.useDefaults, n.exports ? n.exports = t : (t._prevLogger = e.Logger, t.noConflict = function() { return e.Logger = t._prevLogger, t; }, e.Logger = t); })(Vs); }(Gt)), Gt.exports; } var qs = js(); const it = /* @__PURE__ */ Ct(qs), ns = "0.6.1", Tt = 60; var rs; const Gs = ((rs = window == null ? void 0 : window.navigator) == null ? void 0 : rs.userAgent) || "No user agent available"; let kt = "", At = "", Dt = "", ht = "", pt = "", zn = "", Mt = "", Lt = 0; const Pt = []; function Hs(n) { function e(t, r) { return { ts: Math.round(r.timestamp) || "", // Timestamp to the nearest millisecond ot: t === "audio" ? "a" : "v", // 'a' for audio, 'v' for video bl: r.jitterBufferDelay || 0, // Buffer length from jitterBufferDelay, default to 0 if not available br: Math.round(r.bitrateBitsPerSecond || 0), // Bitrate, rounded to nearest integer, default to 0 if not available pld: r.packetsLostDeltaPerSecond || 0, // Packets lost delta per second, default to 0 if not available j: r.jitter || 0, // Jitter, default to 0 if not available mtp: r.packetRate || 0, // Measured throughput, approximated by packet rate, default to 0 if not available mid: r.mid || "", // Media ID or track identifier, default to empty string if not available mimeType: r.mimeType || "" // MIME type of the media stream, default to empty string if not available }; } return n.stats = n.stats.reduce((t, r) => { const i = r.audio.inbounds.length !== 0 ? r.audio.inbounds.map((c) => e("audio", c)) : r.audio.outbounds.map((c) => e("audio", c)), o = r.video.inbounds.length !== 0 ? r.video.inbounds.map((c) => e("video", c)) : r.video.outbounds.map((c) => e("video", c)); return t.concat([...i, ...o]); }, []), n; } const Re = { initAccountId: (n) => { kt = kt === "" ? n : kt; }, initStreamName: (n) => { At = At === "" ? n : At; }, initSubscriberId: (n) => { Dt = Dt === "" ? n : Dt; }, initStreamViewId: (n) => { ht = ht === "" ? n : ht; }, initFeedId: (n) => { pt = pt === "" ? n : pt; }, setConnectionTime: (n) => { Lt = Lt === 0 ? n : Lt; }, setConnectionState: (n) => { zn = n; }, setClusterId: (n) => { Mt = Mt === "" ? n : Mt; }, addStats: (n) => { Pt.length === Tt && Pt.shift(), Pt.push(n); }, get: (n = Tt, e = "JSON") => { let t; !Number.isInteger(n) || n > Tt || n <= 0 ? t = Tt : t = n; const r = { client: "@millicast/millicast-sdk", version: ns, timestamp: (/* @__PURE__ */ new Date()).toISOString(), userAgent: Gs, clusterId: Mt, accountId: kt, streamName: At, subscriberId: Dt, connection: zn, stats: Pt.slice(-t), connectionDurationMs: (/* @__PURE__ */ new Date()).getTime() - Lt }; return pt !== "" ? r.feedId = pt : ht !== "" && (r.streamViewId = ht), e === "CMCD" ? Hs(r) : r; } }; it.useDefaults({ defaultLevel: it.TRACE }); const Ut = ["TRACE", "DEBUG", "INFO", "WARN", "ERROR"], is = (n, e) => { n.unshift("[".concat(e.name || "Global", "] ").concat((/* @__PURE__ */ new Date()).toISOString(), " - ").concat(e.level.name, " -")); }, ss = (n, e) => e ? n.value >= et[e].value : n.value >= Ht.value, Ws = (n, e) => { n = Array.prototype.slice.call(n), n = n.map((t) => typeof t == "object" ? JSON.stringify(t) : t), is(n, e), bt !== 0 ? (lt.push(n.join(" ")), lt.length >= bt && (lt = lt.slice(-bt))) : lt = []; }, $s = it.createDefaultHandler({ formatter: is }); it.setHandler((n, e) => { Ws(n, e), ss(e.level, e.name) && $s(n, e); for (const { handler: t, level: r } of os) e.level.value >= r.value && t(n, e); }); const zs = 1e4; let bt = zs, lt = [], Ht = it.OFF; const et = {}, os = [], Ge = Be(ie({}, it), { enabledFor: ss, /** * @function * @name getHistory * @description Get all logs generated during a session. * All logs are recollected besides the log level selected by the user. * @returns {Array<String>} All logs recollected from level TRACE. * @example Logger.getHistory() * // Outupt * // [ * // "[Director] 2021-04-05T14:09:26.625Z - Getting publisher connection data for stream name: 1xxx2", * // "[Director] 2021-04-05T14:09:27.064Z - Getting publisher response", * // "[Publish] 2021-04-05T14:09:27.066Z - Broadcasting" * // ] */ getHistory: () => lt, /** * @function * @name getHistoryMaxSize * @description Get the maximum count of logs preserved during a session. * @example Logger.getHistoryMaxSize() */ getHistoryMaxSize: () => bt, /** * @function * @name setHistoryMaxSize * @description Set the maximum count of logs to preserve during a session. * By default it is set to 10000. * @param {Number} maxSize - Max size of log history. Set 0 to disable history or -1 to unlimited log history. * @example Logger.setHistoryMaxSize(100) */ setHistoryMaxSize: (n) => { bt = n; }, /** * @function * @name setLevel * @description Set log level to all loggers. * @param {LogLevel} level - New log level to be set. * @example * // Global Level * Logger.setLevel(Logger.DEBUG) * * // Module Level * Logger.get('Publish').setLevel(Logger.DEBUG) */ setLevel: (n) => { Ht = n; for (const e in et) et[e] = n; }, /** * @function * @name getLevel * @description Get global current logger level. * Also you can get the level of any particular logger. * @returns {LogLevel} * @example * // Global Level * Logger.getLevel() * // Output * // {value: 2, name: 'DEBUG'} * * // Module Level * Logger.get('Publish').getLevel() * // Output * // {value: 5, name: 'WARN'} */ getLevel: () => Ht, /** * @function * @name get * @description Gets or creates a named logger. Named loggers are used to group log messages * that refers to a common context. * @param {String} name * @returns {Object} Logger object with same properties and functions as Logger except * history and handlers related functions. * @example * const myLogger = Logger.get('MyLogger') * // Set logger level * myLogger.setLevel(Logger.DEBUG) * * myLogger.debug('This is a debug log') * myLogger.info('This is a info log') * myLogger.warn('This is a warning log') * * // Get logger level * myLogger.getLevel() * // {value: 3, name: 'INFO'} */ get: (n) => { et[n] || (et[n] = Ht); const e = it.get(n); return e.setLevel = (t) => { et[n] = t; }, e.getLevel = () => et[n], e; }, /** * Callback which handles log messages. * * @callback loggerHandler * @global * @param {any[]} messages - Arguments object with the supplied log messages. * @param {Object} context * @param {LogLevel} context.level - The currrent log level. * @param {String?} context.name - The optional current logger name. */ /** * @function * @name setHandler * @description Add your custom log handler to Logger at the specified level. * @param {loggerHandler} handler - Your custom log handler function. * @param {LogLevel} level - Log level to filter messages. * @example * const myHandler = (messages, context) => { * // You can filter by logger * if (context.name === 'Publish') { * sendToMyLogger(messages[0]) * } * * // You can filter by logger level * if (context.level.value >= Logger.INFO.value) { * sendToMyLogger(messages[0]) * } * } * * Logger.setHandler(myHandler, Logger.INFO) */ setHandler: (n, e) => { os.push({ handler: n, level: e }); }, /** * @function * @name diagnose * @description Returns diagnostics information about the connection and environment, formatted according to the specified parameters. * @param {Object | Number} config - Configuration object for the diagnostic parameters * @param {Number} [config.statsCount = 60] - Number of stats objects to be included in the diagnostics report. * @param {Number} [config.historySize = 1000] - Amount of history messages to be returned. * @param {String} [config.minLogLevel] - Levels of history messages to be included. * examples of minLogLevel values in level order: * 1 - TRACE * 2 - DEBUG * 3 - INFO * 4 - WARN * 5 - ERROR * If 'INFO' (3) given, return INFO (3), WARN (4), and ERROR (5) level messages. * @param {String} [config.statsFormat='JSON'] - Format of the stats objects in the diagnostics report. Use Logger.JSON or Logger.CMCD. * @returns {Object} An object containing relevant diagnostics information such as userAgent, SDK version, and stats data. * @example * // Example using default parameters * const diagnosticsDefault = Logger.diagnose(); * * // Example specifying statsCount and format * const diagnostics = Logger.diagnose({ statsCount: 30, minLogLevel: 'INFO', format: Logger.CMCD }); * * // Output: Diagnostics object with specified configuration */ diagnose: (n = {}) => { let e; const t = { statsCount: 60, historySize: 1e3, minLogLevel: "TRACE", statsFormat: "JSON" }; typeof n == "number" ? (t.statsCount = n, e = t) : e = ie(ie({}, t), n); const { statsCount: r, historySize: i, minLogLevel: o, statsFormat: c } = e, a = Re.get(r, c), f = Ge.getHistory(); if (!Number.isInteger(i) || i <= 0) throw new Error("Invalid Argument Exception : historySize must be a positive integer."); if (!Ut.includes(o.toUpperCase())) throw new Error('Invalid Argument Exception : the minLogLevel parameter only excepts "trace", "debug", "info", "warn", and "error" as arguments.'); if (Ut.includes(o.toUpperCase())) { const d = Ut.slice(Ut.indexOf(o.toUpperCase())), l = f.filter((w) => d.some((g) => w.includes(g))); a.history = l.slice(-i); } return a; }, JSON: "JSON", CMCD: "CMCD", /** * @var * @name VERSION * @description Returns the current SDK version. */ VERSION: ns }); var Bt = { exports: {} }, Kn; function cn() { if (Kn) return Bt.exports; Kn = 1; var n = typeof Reflect == "object" ? Reflect : null, e = n && typeof n.apply == "function" ? n.apply : function(S, E, b) { return Function.prototype.apply.call(S, E, b); }, t; n && typeof n.ownKeys == "function" ? t = n.ownKeys : Object.getOwnPropertySymbols ? t = function(S) { return Object.getOwnPropertyNames(S).concat(Object.getOwnPropertySymbols(S)); } : t = function(S) { return Object.getOwnPropertyNames(S); }; function r(v) { console && console.warn && console.warn(v); } var i = Number.isNaN || function(S) { return S !== S; }; function o() { o.init.call(this); } Bt.exports = o, Bt.exports.once = M, o.EventEmitter = o, o.prototype._events = void 0, o.prototype._eventsCount = 0, o.prototype._maxListeners = void 0; var c = 10; function a(v) { if (typeof v != "function") throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof v); } Object.defineProperty(o, "defaultMaxListeners", { enumerable: !0, get: function() { return c; }, set: function(v) { if (typeof v != "number" || v < 0 || i(v)) throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + v + "."); c = v; } }), o.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; }, o.prototype.setMaxListeners = function(S) { if (typeof S != "number" || S < 0 || i(S)) throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + S + "."); return this._maxListeners = S, this; }; function f(v) { return v._maxListeners === void 0 ? o.defaultMaxListeners : v._maxListeners; } o.prototype.getMaxListeners = function() { return f(this); }, o.prototype.emit = function(S) { for (var E = [], b = 1; b < arguments.length; b++) E.push(arguments[b]); var C = S === "error", P = this._events; if (P !== void 0) C = C && P.error === void 0; else if (!C) return !1; if (C) { var k; if (E.length > 0 && (k = E[0]), k instanceof Error) throw k; var O = new Error("Unhandled error." + (k ? " (" + k.message + ")" : "")); throw O.context = k, O; } var J = P[S]; if (J === void 0) return !1; if (typeof J == "function") e(J, this, E); else for (var H = J.length, ee = m(J, H), b = 0; b < H; ++b) e(ee[b], this, E); return !0; }; function d(v, S, E, b) { var C, P, k; if (a(E), P = v._events, P === void 0 ? (P = v._events = /* @__PURE__ */ Object.create(null), v._eventsCount = 0) : (P.newListener !== void 0 && (v.emit( "newListener", S, E.listener ? E.listener : E ), P = v._events), k = P[S]), k === void 0) k = P[S] = E, ++v._eventsCount; else if (typeof k == "function" ? k = P[S] = b ? [E, k] : [k, E] : b ? k.unshift(E) : k.push(E), C = f(v), C > 0 && k.length > C && !k.warned) { k.warned = !0; var O = new Error("Possible EventEmitter memory leak detected. " + k.length + " " + String(S) + " listeners added. Use emitter.setMaxListeners() to increase limit"); O.name = "MaxListenersExceededWarning", O.emitter = v, O.type = S, O.count = k.length, r(O); } return v; } o.prototype.addListener = function(S, E) { return d(this, S, E, !1); }, o.prototype.on = o.prototype.addListener, o.prototype.prependListener = function(S, E) { return d(this, S, E, !0); }; function l() { 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 w(v, S, E) { var b = { fired: !1, wrapFn: void 0, target: v, type: S, listener: E }, C = l.bind(b); return C.listener = E, b.wrapFn = C, C; } o.prototype.once = function(S, E) { return a(E), this.on(S, w(this, S, E)), this; }, o.prototype.prependOnceListener = function(S, E) { return a(E), this.prependListener(S, w(this, S, E)), this; }, o.prototype.removeListener = function(S, E) { var b, C, P, k, O; if (a(E), C = this._events, C === void 0) return this; if (b = C[S], b === void 0) return this; if (b === E || b.listener === E) --this._eventsCount === 0 ? this._events = /* @__PURE__ */ Object.create(null) : (delete C[S], C.removeListener && this.emit("removeListener", S, b.listener || E)); else if (typeof b != "function") { for (P = -1, k = b.length - 1; k >= 0; k--) if (b[k] === E || b[k].listener === E) { O = b[k].listener, P = k; break; } if (P < 0) return this; P === 0 ? b.shift() : I(b, P), b.length === 1 && (C[S] = b[0]), C.removeListener !== void 0 && this.emit("removeListener", S, O || E); } return this; }, o.prototype.off = o.prototype.removeListener, o.prototype.removeAllListeners = function(S) { var E, b, C; if (b = this._events, b === void 0) return this; if (b.removeListener === void 0) return arguments.length === 0 ? (this._events = /* @__PURE__ */ Object.create(null), this._eventsCount = 0) : b[S] !== void 0 && (--this._eventsCount === 0 ? this._events = /* @__PURE__ */ Object.create(null) : delete b[S]), this; if (arguments.length === 0) { var P = Object.keys(b), k; for (C = 0; C < P.length; ++C) k = P[C], k !== "removeListener" && this.removeAllListeners(k); return this.removeAllListeners("removeListener"), this._events = /* @__PURE__ */ Object.create(null), this._eventsCount = 0, this; } if (E = b[S], typeof E == "function") this.removeListener(S, E); else if (E !== void 0) for (C = E.length - 1; C >= 0; C--) this.removeListener(S, E[C]); return this; }; function g(v, S, E) { var b = v._events; if (b === void 0) return []; var C = b[S]; return C === void 0 ? [] : typeof C == "function" ? E ? [C.listener || C] : [C] : E ? R(C) : m(C, C.length); } o.prototype.listeners = function(S) { return g(this, S, !0); }, o.prototype.rawListeners = function(S) { return g(this, S, !1); }, o.listenerCount = function(v, S) { return typeof v.listenerCount == "function" ? v.listenerCount(S) : p.call(v, S); }, o.prototype.listenerCount = p; function p(v) { var S = this._events; if (S !== void 0) { var E = S[v]; if (typeof E == "function") return 1; if (E !== void 0) return E.length; } return 0; } o.prototype.eventNames = function() { return this._eventsCount > 0 ? t(this._events) : []; }; function m(v, S) { for (var E = new Array(S), b = 0; b < S; ++b) E[b] = v[b]; return E; } function I(v, S) { for (; S + 1 < v.length; S++) v[S] = v[S + 1]; v.pop(); } function R(v) { for (var S = new Array(v.length), E = 0; E < S.length; ++E) S[E] = v[E].listener || v[E]; return S; } function M(v, S) { return new Promise(function(E, b) { function C(k) { v.removeListener(S, P), b(k); } function P() { typeof v.removeListener == "function" && v.removeListener("error", C), E([].slice.call(arguments)); } F(v, S, P, { once: !0 }), S !== "error" && U(v, C, { once: !0 }); }); } function U(v, S, E) { typeof v.on == "function" && F(v, "error", S, E); } function F(v, S, E, b) { if (typeof v.on == "function") b.once ? v.once(S, E) : v.on(S, E); else if (typeof v.addEventListener == "function") v.addEventListener(S, function C(P) { b.once && v.removeEventListener(S, C), E(P); }); else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof v); } return Bt.exports; } var Ks = cn(); const Zt = /* @__PURE__ */ Ct(Ks); var Ft = { exports: {} }, Xn; function Xs() { if (Xn) return Ft.exports; Xn = 1, Ft.exports = e, Ft.exports.filter = t; var n = cn().EventEmitter; function e(r, i, o) { Array.isArray(o) || (o = [o]); var c = []; return o.forEach(function(a) { var f = function() { var d = [].slice.call(arguments); d.unshift(a), i.emit.apply(i, d); }; c.push(f), r.on(a, f); }), function() { o.forEach(function(f, d) { r.removeListener(f, c[d]); }); }; } function t(r, i) { var o = new n(); return e(r, o, i), o; } return Ft.exports; } var Ys = Xs(); const Kt = /* @__PURE__ */ Ct(Ys); var ur = { exports: {} }; /*! For license information please see webrtc-stats.js.LICENSE.txt */ var Yn; function Js() { return Yn || (Yn = 1, function(n, e) { (function(t, r) { n.exports = r(); })(self, () => { return t = { 7: (i) => { var o, c = typeof Reflect == "object" ? Reflect : null, a = c && typeof c.apply == "function" ? c.apply : function(v, S, E) { return Function.prototype.apply.call(v, S, E); }; o = c && typeof c.ownKeys == "function" ? c.ownKeys : Object.getOwnPropertySymbols ? function(v) { return Object.getOwnPropertyNames(v).concat(Object.getOwnPropertySymbols(v)); } : function(v) { return Object.getOwnPropertyNames(v); }; var f = Number.isNaN || function(v) { return v != v; }; function d() { d.init.call(this); } i.exports = d, i.exports.once = function(v, S) { return new Promise(function(E, b) { function C(k) { v.removeListener(S, P), b(k); } function P() { typeof v.removeListener == "function" && v.removeListener("error", C), E([].slice.call(arguments)); } F(v, S, P, { once: !0 }), S !== "error" && function(k, O) { typeof k.on == "function" && F(k, "error", O, { once: !0 }); }(v, C); }); }, d.EventEmitter = d, d.prototype._events = void 0, d.prototype._eventsCount = 0, d.prototype._maxListeners = void 0; var l = 10; function w(v) { if (typeof v != "function") throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof v); } function g(v) { return v._maxListeners === void 0 ? d.defaultMaxListeners : v._maxListeners; } function p(v, S, E, b) { var C, P, k, O; if (w(E), (P = v._events) === void 0 ? (P = v._events = /* @__PURE__ */ Object.create(null), v._eventsCount = 0) : (P.newListener !== void 0 && (v.emit("newListener", S, E.listener ? E.listener : E), P = v._events), k = P[S]), k === void 0) k = P[S] = E, ++v._eventsCount; else if (typeof k == "function" ? k = P[S] = b ? [E, k] : [k, E] : b ? k.unshift(E) : k.push(E), (C = g(v)) > 0 && k.length > C && !k.warned) { k.warned = !0; var J = new Error("Possible EventEmitter memory leak detected. " + k.length + " " + String(S) + " listeners added. Use emitter.setMaxListeners() to increase limit"); J.name = "MaxListenersExceededWarning", J.emitter = v, J.type = S, J.count = k.length, O = J, console && console.warn && console.warn(O); } return v; } function m() { 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 I(v, S, E) { var b = { fired: !1, wrapFn: void 0, target: v, type: S, listener: E }, C = m.bind(b); return C.listener = E, b.wrapFn = C, C; } function R(v, S, E) { var b = v._events; if (b === void 0) return []; var C = b[S]; return C === void 0 ? [] : typeof C == "function" ? E ? [C.listener || C] : [C] : E ? function(P) { for (var k = new Array(P.length), O = 0; O < k.length; ++O) k[O] = P[O].listener || P[O]; return k; }(C) : U(C, C.length); } function M(v) { var S = this._events; if (S !== void 0) { var E = S[v]; if (typeof E == "function") return 1; if (E !== void 0) return E.length; } return 0; } function U(v, S) { for (var E = new Array(S), b = 0; b < S; ++b) E[b] = v[b]; return E; } function F(v, S, E, b) { if (typeof v.on == "function") b.once ? v.once(S, E) : v.on(S, E); else { if (typeof v.addEventListener != "function") throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof v); v.addEventListener(S, function C(P) { b.once && v.removeEventListener(S, C), E(P); }); } } Object.defineProperty(d, "defaultMaxListeners", { enumerable: !0, get: function() { return l; }, set: function(v) { if (typeof v != "number" || v < 0 || f(v)) throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + v + "."); l = v; } }), d.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; }, d.prototype.setMaxListeners = function(v) { if (typeof v != "number" || v < 0 || f(v)) throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + v + "."); return this._maxListeners = v, this; }, d.prototype.getMaxListeners = function() { return g(this); }, d.prototype.emit = function(v) { for (var S = [], E = 1; E < arguments.length; E++) S.push(arguments[E]); var b = v === "error", C = this._events; if (C !== void 0) b = b && C.error === void 0; else if (!b) return !1; if (b) { var P; if (S.length > 0 && (P = S[0]), P instanceof Error) throw P; var k = new Error("Unhandled error." + (P ? " (" + P.message + ")" : "")); throw k.context = P, k; } var O = C[v]; if (O === void 0) return !1; if (typeof O == "function") a(O, this, S); else { var J = O.length, H = U(O, J); for (E = 0; E < J; ++E) a(H[E], this, S); } return !0; }, d.prototype.addListener = function(v, S) { return p(this, v, S, !1); }, d.prototype.on = d.prototype.addListener, d.prototype.prependListener = function(v, S) { return p(this, v, S, !0); }, d.prototype.once = function(v, S) { return w(S), this.on(v, I(this, v, S)), this; }, d.prototype.prependOnceListener = function(v, S) { return w(S), this.prependListener(v, I(this, v, S)), this; }, d.prototype.removeListener = function(v, S) { var E, b, C, P, k; if (w(S), (b = this._events) === void 0) return this; if ((E = b[v]) === void 0) return this; if (E === S || E.listener === S) --this._eventsCount == 0 ? this._events = /* @__PURE__ */ Object.create(null) : (delete b[v], b.removeListener && this.emit("removeListener", v, E.listener || S)); else if (typeof E != "function") { for (C = -1, P = E.length - 1; P >= 0; P--) if (E[P] === S || E[P].listener === S) { k = E[P].listener, C = P; break; } if (C < 0) return this; C === 0 ? E.shift() : function(O, J) { for (; J + 1 < O.length; J++) O[J] = O[J + 1]; O.pop(); }(E, C), E.length === 1 && (b[v] = E[0]), b.removeListener !== void 0 && this.emit("removeListener", v, k || S); } return this; }, d.prototype.off = d.prototype.removeListener, d.prototype.removeAllListeners = function(v) { var S, E, b; if ((E = this._events) === void 0) return this; if (E.removeListener === void 0) return arguments.length === 0 ? (this._events = /* @__PURE__ */ Object.create(null), this._eventsCount = 0) : E[v] !== void 0 && (--this._eventsCount == 0 ? this._events = /* @__PURE__ */ Object.create(null) : delete E[v]), this; if (arguments.length === 0) { var C, P = Object.keys(E); for (b = 0; b < P.length; ++b) (C = P[b]) !== "removeListener" && this.removeAllListeners(C); return this.removeAllListeners("removeListener"), this._events = /* @__PURE__ */ Object.create(null), this._eventsCount = 0, this; } if (typeof (S = E[v]) == "function") this.removeListener(v, S); else if (S !== void 0) for (b = S.length - 1; b >= 0; b--) this.removeListener(v, S[b]); return this; }, d.prototype.listeners = function(v) { return R(this, v, !0); }, d.prototype.rawListeners = function(v) { return R(this, v, !1); }, d.listenerCount = function(v, S) { return typeof v.listenerCount == "function" ? v.listenerCount(S) : M.call(v, S); }, d.prototype.listenerCount = M, d.prototype.eventNames = function() { return this._eventsCount > 0 ? o(this._events) : []; }; }, 156: function(i, o, c) { var a = this && this.__createBinding || (Object.create ? function(w, g, p, m) { m === void 0 && (m = p); var I = Object.getOwnPropertyDescriptor(g, p); I && !("get" in I ? !g.__esModule : I.writable || I.configurable) || (I = { enumerable: !0, get: function() { return g[p]; } }), Object.defineProperty(w, m, I); } : function(w, g, p, m) { m === void 0 && (m = p), w[m] = g[p]; }), f = this && this.__exportStar || function(w, g) { for (var p in w) p === "default" || Object.prototype.hasOwnProperty.call(g, p) || a(g, w, p); }, d = this && this.__importDefault || function(w) { return w && w.__esModule ? w : { default: w }; }; Object.defineProperty(o, "__esModule", { value: !0 }), o.Logger = void 0; var l = c(586); Object.defineProperty(o, "Logger", { enumerable: !0, get: function() { return d(l).default; } }), f(c(284), o), f(c(280), o), f(c(738), o), f(c(767), o); }, 185: (i, o) => { Object.defineProperty(o, "__esModule", { value: !0 }), o.calculatePacketsLostRatio = o.calculateRate = o.getMediaKind = void 0, o.getMediaKind = (c) => { let a = c.kind || c.mediaType; return ["audio", "video"].includes(a) || c.type !== "inbound-rtp" || (a = c.id.toLocaleLowerCase().includes("video") ? "video" : "audio"), a; }, o.calculateRate = (c, a, f, d) => f && d ? (a - d) / ((c - f) / 1e3) : 0, o.calculatePacketsLostRatio = (c, a, f, d) => { const l = c - (f != null ? f : 0), w = l + (a - (d != null ? d : 0)); return w === 0 ? 0 : l / w; }; }, 280: (i, o) => { Object.defineProperty(o, "__esModule", { value: !0 }); }, 284: function(i, o, c) { var a, f, d, l, w, g, p, m, I, R, M, U, F, v, S, E, b = this && this.__awaiter || function(j, B, V, X) { return new (V || (V = Promise))(function(Y, _) { function N(z) { try { W(X.next(z)); } catch (K) { _(K); } } function q(z) { try { W(X.throw(z)); } catch (K) { _(K); } } function W(z) { var K; z.done ? Y(z.value) : (K = z.value, K instanceof V ? K : new V(function(ne) { ne(K); })).then(N, q); } W((X = X.apply(j, B || [])).next()); }); }, C = this && this.__classPrivateFieldSet || function(j, B, V, X, Y) { if (X === "m") throw new TypeError("Private method is not writable"); if (X === "a" && !Y) throw new TypeError("Private accessor was defined without a setter"); if (typeof B == "function" ? j !== B || !Y : !B.has(j)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return X === "a" ? Y.call(j, V) : Y ? Y.value = V : B.set(j, V), V; }, P = this && this.__classPrivateFieldGet || function(j, B, V, X) { if (V === "a" && !X) throw new TypeError("Private accessor was defined without a getter"); if (typeof B == "function" ? j !== B || !X : !B.has(j)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return V === "m" ? X : V === "a" ? X.call(j) : X ? X.value : B.get(j); }, k = this && this.__importDefault || function(j) { return j && j.__esModule ? j : { default: j }; }; Object.defineProperty(o, "__esModule", { value: !0 }), o.WebRTCStats = void 0; const O = c(7), J = k(c(586)), H = c(738), ee = c(185); class G extends O.EventEmitter { constructor(B) { super(), a.add(this), f.set(this, void 0), d.set(this, void 0), l.set(this, void 0), w.set(this, null), g.set(this, void 0), p.set(this, null), this.start = () => { P(this, g, "f").info("WebRTC statistics collection is starting..."), C(this, p, null, "f"), C(this, w, setInterval(P(this, m, "f"), P(this, d, "f")), "f"); }, this.stop = () => { P(this, w, "f") && (clearInterval(P(this, w, "f")), C(this, w, null, "f"), P(this, g, "f").info("WebRTC statistics collection has stopped.")); }, m.set(this, () => b(this, void 0, void 0, function* () { let V, X; try { P(this, g, "f").trace("Requesting WebRTC statistics..."), V = yield P(this, f, "f").call(this), X = (/* @__PURE__ */ new Date()).toISOString(); } catch (N) { return P(this, g, "f").error("Problem collecting the WebRTC statistics.", N), void this.emit("error", "Problem collecting the WebRTC statistics - ".concat(N)); } const Y = Array.from(V.values()), _ = { timestamp: X, input: { audio: [], video: [] }, output: { audio: [], video: [] } }; P(this, l, "f") && (_.rawStats = V); for (let N = 0; N < Object.keys(Y).length; N++) { const q = Y[N]; switch (q.type) { case "outbound-rtp": const W = q, z = (0, ee.getMediaKind)(W); z === "audio" ? yield P(this, a, "m", M).call(this, V, W, _) : z === "video" && (yield P(this, a, "m", U).call(this, V, W, _)); break; case "inbound-rtp": const K = q; let ne = (0, ee.getMediaKind)(K); ne === "audio" ? yield P(this, a, "m", v).call(this, V, K, _) : ne === "video" && (yield P(this, a, "m", S).call(this, V, K, _)); break; case "candidate-pair": const he = q; he.nominated && P(this, a, "m", E).call(this, he, _); } } C(this, p, _, "f"), this.emit("stats", _); })), C(this, g, J.default.get("WebRTCStats"), "f"), C(this, f, B.getStats, "f"), C(this, d, B.getStatsInterval || 1e3, "f"), C(this, l, !!B.includeRawStats, "f"); } } o.WebRTCStats = G, f = /* @__PURE__ */ new WeakMap(), d = /* @__PURE__ */ new WeakMap(), l = /* @__PURE__ */ new WeakMap(), w = /* @__PURE__ */ new WeakMap(), g = /* @__PURE__ */ new WeakMap(), p = /* @__PURE__ */ new WeakMap(), m = /* @__PURE__ */ new WeakMap(), a = /* @__PURE__ */ new WeakSet(), I = function(j, B) { if (B) { const V = j.get(B); if (V) return { mimeType: V.mimeType }; } return {}; }, R = function(j, B, V) { return b(this, void 0, void 0, function* () { var X, Y, _, N; const q = (0, ee.calculateRate)(B.timestamp, B.bytesSent, V == null ? void 0 : V.timestamp, V == null ? void 0 : V.totalBytesSent), W = (0, ee.calculateRate)(B.timestamp, B.packetsSent, V == null ? void 0 : V.timestamp, V == null ? void 0 : V.totalPacketsSent), z = P(this, a, "m", I).call(this, j, B.codecId); return Object.assign({ id: B.id, timestamp: B.timestamp, mid: B.mid, totalBytesSent: B.bytesSent, bytesSentDelta: B.bytesSent - ((X = V == null ? void 0 : V.totalBytesSent) !== null && X !== void 0 ? X : 0), totalPacketsSent: B.packetsSent, packetsSentDelta: B.packetsSent - ((Y = V == null ? void 0 : V.totalPacketsSent) !== null && Y !== void 0 ? Y : 0), bitrate: q, packetRate: W, targetBitrate: B.targetBitrate, retransmittedPacketsSent: B.retransmittedPacketsSent, retransmittedPacketsSentDelta: B.retransmittedPacketsSent - ((_ = V == null ? void 0 : V.retransmittedPacketsSent) !== null && _ !== void 0 ? _ : 0), retransmittedBytesSent: B.retransmittedBytesSent, retransmittedBytesSentDelta: B.retransmittedBytesSent - ((N = V == null ? void 0 : V.retransmittedBytesSent) !== null && N !== void 0 ? N : 0) }, z); }); }, M = function(j, B, V) { return b(this, void 0, void 0, function* () { var X; const Y = (X = P(this, p, "f")) === null || X === void 0 ? void 0 : X.output.audio.find((q) => q.id === B.id); if (Y && B.timestamp - Y.timestamp <= 0) return; const _ = yield P(this, a, "m", R).call(this, j, B, Y), N = Object.assign({}, _); V.output.audio.push(N); }); }, U = function(j, B, V) { return b(this, void 0, void 0, function* () { var X; const Y = (X = P(this, p, "f")) === null || X === void 0 ? void 0 : X.output.video.find((W) => W.id === B.id); if (Y && B.timestamp - Y.timestamp <= 0) return; const _ = yield P(this, a, "m", R).call(this, j, B, Y); let N = H.QualityLimitationReason.none; B.qualityLimitationReason && (N = B.qualityLimitationReason); const q = Object.assign(Object.assign({}, _), { frameWidth: B.frameWidth, frameHeight: B.frameHeight, framesPerSecond: B.framesPerSecond, framesSent: B.framesSent, qualityLimitationReason: N, qualityLimitationDurations: B.qualityLimitationDurations }); V.output.video.push(q); }); }, F = function(j, B, V) { return b(this, void 0, void 0, function* () { var X, Y; const _ = (0, ee.calculateRate)(B.timestamp, B.bytesReceived, V == null ? void 0 : V.timestamp, V == null ? void 0 : V.totalBytesReceived), N = (0, ee.calculateRate)(B.timestamp, B.packetsReceived, V == null ? void 0 : V.timestamp, V == null ? void 0 : V.totalPacketsReceived), q = (0, ee.calculatePacketsLostRatio)(B.packetsLost, B.packetsReceived, V == null ? void 0 : V.totalPacketsLost, V == null ? void 0 : V.totalPacketsReceived), W = ((X = B.packetsLost) !== null && X !== void 0 ? X : 0) - ((Y = V == null ? void 0 : V.totalPacketsLost) !== null && Y !== void 0 ? Y : 0), z = P(this, a, "m", I).call(this, j, B.codecId); return Object.assign({ id: B.id, timestamp: B.timestamp, mid: B.mid, trackIdentifier: B.trackIdentifier, jitter: B.jitter, jitterBufferDelay: B.jitterBufferDelay, jitterBufferEmittedCount: B.jitterBufferEmittedCount, totalBytesReceived: B.bytesReceived, totalPacketsReceived: B.packetsReceived, totalPacketsLost: B.packetsLost, bitrate: _, packetRate: N, packetLossRatio: q, packetLossDelta: W }, z); }); }, v = function(j, B, V) { return b(this, void 0, void 0, function* () { var X; const Y = (X = P(this, p, "f")) === null || X === void 0 ? void 0 : X.input.audio.find((N) => N.id === B.id); if (Y && B.timestamp - Y.timestamp <= 0) return; const _ = yield P(this, a, "m", F).call(this, j, B, Y); V.input.audio.push(_); }); }, S = function(j, B, V) { return b(this, void 0, void 0, function* () { var X; const Y = (X = P(this, p, "f")) === null || X === void 0 ? void 0 : X.input.video.find((q) => q.id === B.id); if (Y && B.timestamp - Y.timestamp <= 0) return; const _ = yield P(this, a, "m", F).call(this, j, B, Y), N = Object.assign(Object.assign({}, _), { keyFramesDecoded: B.keyFramesDecoded, frameHeight: B.frameHeight, frameWidth: B.frameWidth, framesDecoded: B.framesDecoded, framesDropped: B.framesDropped, framesPerSecond: B.framesPerSecond, framesReceived: B.framesReceived }); V.input.video.push(N); }); }, E = function(j, B) { B.totalRoundTripTime = j.totalRoundTripTime, B.currentRoundTripTime = j.currentRoundTripTime, B.responsesReceived = j.responsesReceived, B.availableOutgoingBitrate = j.availableOutgoingBitrate, B.availableIncomingBitrate = j.availableIncomingBitrate; }; }, 586: function(i, o, c) { var a, f; (function() { var d, l = { VERSION: "1.6.1" }, w = {}, g = function(U, F) { return function() { return F.apply(U, arguments); }; }, p = function() { var U, F, v = arguments, S = v[0]; for (F = 1; F < v.length; F++) for (U in v[F]) !(U in S) && v[F].hasOwnProperty(U) && (S[U] = v[F][U]); return S; }, m = function(U, F) { return { value: U, name: F }; }; l.TRACE = m(1, "TRACE"), l.DEBUG = m(2, "DEBUG"), l.INFO = m(3, "INFO"), l.TIME = m(4, "TIME"), l.WARN = m(5, "WARN"), l.ERROR = m(8, "ERROR"), l.OFF = m(99, "OFF"); var I = function(U) { this.context = U, this.setLevel(U.filterLevel), this.log = this.info; }; I.prototype = { setLevel: function(U) { U && "value" in U && (this.context.filterLevel = U); }, getLevel: function() { return this.context.filterLevel; }, enabledFor: function(U) { var F = this.context.filterLevel; return U.value >= F.value; }, trace: function() { this.invoke(l.TRACE, arguments); }, debug: function() { this.invoke(l.DEBUG, arguments); }, info: function() { this.invoke(l.INFO, arguments); }, warn: function() { this.invoke(l.WARN, arguments); }, error: function() { this.invoke(l.ERROR, arguments); }, time: function(U) { typeof U == "string" && U.length > 0 && this.invoke(l.TIME, [U, "start"]); }, timeEnd: function(U) { typeof U == "string" && U.length > 0 && this.invoke(l.TIME, [U, "end"]); }, invoke: function(U, F) { d && this.enabledFor(U) && d(F, p({ level: U }, this.context)); } }; var R, M = new I({ filterLevel: l.OFF }); (R = l).enabledFor = g(M, M.enabledFor), R.trace = g(M, M.trace), R.debug = g(M, M.debug), R.time = g(M, M.time), R.timeEnd = g(M, M.timeEnd), R.info = g(M, M.info), R.warn = g(M, M.warn), R.error = g(M, M.error), R.log = R.info, l.setHandler = function(U) { d = U; }, l.setLevel = function(U) { for (var F in M.setLevel(U), w) w.hasOwnProperty(F) && w[F].setLevel(U); }, l.getLevel = function() { return M.getLevel(); }, l.get = function(U) { return w[U] || (w[U] = new I(p({ name: U }, M.context))); }, l.createDefaultHandler = function(U) { (U = U || {}).formatter = U.formatter || function(S, E) { E.name && S.unshift("[" + E.name + "]"); }; var F = {}, v = function(S, E) { Function.prototype.apply.call(S, console, E); }; return typeof console > "u" ? function() { } : function(S, E) { S = Array.prototype.slice.call(S); var b, C = console.log; E.level === l.TIME ? (b = (E.name ? "[" + E.name + "] " : "") + S[0], S[1] === "start" ? console.time ? console.time(b) : F[b] = (/* @__PURE__ */ new Date()).getTime() : console.timeEnd ? console.timeEnd(b) : v(C, [b + ": " + ((/* @__PURE__ */ new Date()).getTime() - F[b]) + "ms"])) : (E.level === l.WARN && console.warn ? C = console.warn : E.level === l.ERROR && console.error ? C = console.error : E.level === l.INFO && console.info ? C = console.info : E.level === l.DEBUG && console.debug ? C = console.debug : E.level === l.TRACE && console.trace && (C = console.trace), U.formatter(S, E), v(C, S)); }; }, l.useDefaults = function(U) { l.setLevel(U && U.defaultLevel || l.DEBUG), l.setHandler(l.createDefaultHandler(U)); }, l.setDefaults = l.useDefaults, (f = typeof (a = l) == "function" ? a.call(o, c, o, i) : a) === void 0 || (i.exports = f); })(); }, 738: (i, o) => { var c; Object.defineProperty(o, "__esModule", { value: !0 }), o.QualityLimitationReason = void 0, function(a) { a[a.none = 0] = "none", a[a.cpu = 1] = "cpu", a[a.bandwidth = 2] = "bandwidth", a[a.other = 3] = "other"; }(c || (o.QualityLimitationReason = c = {})); }, 767: (i, o) => { Object.defineProperty(o, "__esModule", { value: !0 }); } }, r = {}, function i(o) { var c = r[o]; if (c !== void 0) return c.exports; var a = r[o] = { exports: {} }; return t[o].call(a.exports, a, a.exports, i), a.exports; }(156); var t, r; }); }(ur)), ur.exports; } var Zs = Js(); const mt = Ge.get("PeerConnectionStats"), as = { stats: "stats" }, Qs = (n) => { const c = n, { input: e, output