UNPKG

@millicast/sdk

Version:

SDK for building a realtime broadcaster using the Millicast platform.

1,114 lines 618 kB
var Bi = Object.defineProperty, Gi = Object.defineProperties; var Xi = Object.getOwnPropertyDescriptors; var nr = Object.getOwnPropertySymbols; var es = Object.prototype.hasOwnProperty, ts = Object.prototype.propertyIsEnumerable; var qn = (r, e, t) => e in r ? Bi(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, J = (r, e) => { for (var t in e || (e = {})) es.call(e, t) && qn(r, t, e[t]); if (nr) for (var t of nr(e)) ts.call(e, t) && qn(r, t, e[t]); return r; }, ke = (r, e) => Gi(r, Xi(e)); var tt = (r, e) => { var t = {}; for (var s in r) es.call(r, s) && e.indexOf(s) < 0 && (t[s] = r[s]); if (r != null && nr) for (var s of nr(r)) e.indexOf(s) < 0 && ts.call(r, s) && (t[s] = r[s]); return t; }; var br = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}; function Et(r) { return r && r.__esModule && Object.prototype.hasOwnProperty.call(r, "default") ? r.default : r; } var Ds = { 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. */ (function(r) { (function(e) { var t = {}; t.VERSION = "1.6.1"; var s, d = {}, p = function(h, a) { return function() { return a.apply(h, arguments); }; }, f = function() { var h = arguments, a = h[0], c, l; for (l = 1; l < h.length; l++) for (c in h[l]) !(c in a) && h[l].hasOwnProperty(c) && (a[c] = h[l][c]); return a; }, n = function(h, a) { return { value: h, name: a }; }; t.TRACE = n(1, "TRACE"), t.DEBUG = n(2, "DEBUG"), t.INFO = n(3, "INFO"), t.TIME = n(4, "TIME"), t.WARN = n(5, "WARN"), t.ERROR = n(8, "ERROR"), t.OFF = n(99, "OFF"); var b = function(h) { this.context = h, this.setLevel(h.filterLevel), this.log = this.info; }; b.prototype = { // Changes the current logging level for the logging instance. setLevel: function(h) { h && "value" in h && (this.context.filterLevel = h); }, // 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(h) { var a = this.context.filterLevel; return h.value >= a.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(h) { typeof h == "string" && h.length > 0 && this.invoke(t.TIME, [h, "start"]); }, timeEnd: function(h) { typeof h == "string" && h.length > 0 && this.invoke(t.TIME, [h, "end"]); }, // Invokes the logger callback if it's not being filtered. invoke: function(h, a) { s && this.enabledFor(h) && s(a, f({ level: h }, this.context)); } }; var y = new b({ filterLevel: t.OFF }); (function() { var h = t; h.enabledFor = p(y, y.enabledFor), h.trace = p(y, y.trace), h.debug = p(y, y.debug), h.time = p(y, y.time), h.timeEnd = p(y, y.timeEnd), h.info = p(y, y.info), h.warn = p(y, y.warn), h.error = p(y, y.error), h.log = h.info; })(), t.setHandler = function(h) { s = h; }, t.setLevel = function(h) { y.setLevel(h); for (var a in d) d.hasOwnProperty(a) && d[a].setLevel(h); }, t.getLevel = function() { return y.getLevel(); }, t.get = function(h) { return d[h] || (d[h] = new b(f({ name: h }, y.context))); }, t.createDefaultHandler = function(h) { h = h || {}, h.formatter = h.formatter || function(i, o) { o.name && i.unshift("[" + o.name + "]"); }; var a = {}, c = function(l, i) { Function.prototype.apply.call(l, console, i); }; return typeof console > "u" ? function() { } : function(l, i) { l = Array.prototype.slice.call(l); var o = console.log, m; i.level === t.TIME ? (m = (i.name ? "[" + i.name + "] " : "") + l[0], l[1] === "start" ? console.time ? console.time(m) : a[m] = (/* @__PURE__ */ new Date()).getTime() : console.timeEnd ? console.timeEnd(m) : c(o, [m + ": " + ((/* @__PURE__ */ new Date()).getTime() - a[m]) + "ms"])) : (i.level === t.WARN && console.warn ? o = console.warn : i.level === t.ERROR && console.error ? o = console.error : i.level === t.INFO && console.info ? o = console.info : i.level === t.DEBUG && console.debug ? o = console.debug : i.level === t.TRACE && console.trace && (o = console.trace), h.formatter(l, i), c(o, l)); }; }, t.useDefaults = function(h) { t.setLevel(h && h.defaultLevel || t.DEBUG), t.setHandler(t.createDefaultHandler(h)); }, t.setDefaults = t.useDefaults, r.exports ? r.exports = t : (t._prevLogger = e.Logger, t.noConflict = function() { return e.Logger = t._prevLogger, t; }, e.Logger = t); })(br); })(Ds); var Yi = Ds.exports; const ct = /* @__PURE__ */ Et(Yi), Zs = "0.4.0", sr = 60; var Ls; const zi = ((Ls = window == null ? void 0 : window.navigator) == null ? void 0 : Ls.userAgent) || "No user agent available"; let ir = "", or = "", ar = "", Tt = "", At = "", rs = "", cr = "", lr = 0; const ur = []; function Ki(r) { function e(t, s) { return { ts: Math.round(s.timestamp) || "", // Timestamp to the nearest millisecond ot: t === "audio" ? "a" : "v", // 'a' for audio, 'v' for video bl: s.jitterBufferDelay || 0, // Buffer length from jitterBufferDelay, default to 0 if not available br: Math.round(s.bitrateBitsPerSecond || 0), // Bitrate, rounded to nearest integer, default to 0 if not available pld: s.packetsLostDeltaPerSecond || 0, // Packets lost delta per second, default to 0 if not available j: s.jitter || 0, // Jitter, default to 0 if not available mtp: s.packetRate || 0, // Measured throughput, approximated by packet rate, default to 0 if not available mid: s.mid || "", // Media ID or track identifier, default to empty string if not available mimeType: s.mimeType || "" // MIME type of the media stream, default to empty string if not available }; } return r.stats = r.stats.reduce((t, s) => { const d = s.audio.inbounds.length !== 0 ? s.audio.inbounds.map((f) => e("audio", f)) : s.audio.outbounds.map((f) => e("audio", f)), p = s.video.inbounds.length !== 0 ? s.video.inbounds.map((f) => e("video", f)) : s.video.outbounds.map((f) => e("video", f)); return t.concat([...d, ...p]); }, []), r; } const Ee = { initAccountId: (r) => { ir = ir === "" ? r : ir; }, initStreamName: (r) => { or = or === "" ? r : or; }, initSubscriberId: (r) => { ar = ar === "" ? r : ar; }, initStreamViewId: (r) => { Tt = Tt === "" ? r : Tt; }, initFeedId: (r) => { At = At === "" ? r : At; }, setConnectionTime: (r) => { lr = lr === 0 ? r : lr; }, setConnectionState: (r) => { rs = r; }, setClusterId: (r) => { cr = cr === "" ? r : cr; }, addStats: (r) => { ur.length === sr && ur.shift(), ur.push(r); }, get: (r = sr, e = "JSON") => { let t; !Number.isInteger(r) || r > sr || r <= 0 ? t = sr : t = r; const s = { client: "@millicast/millicast-sdk", version: Zs, timestamp: (/* @__PURE__ */ new Date()).toISOString(), userAgent: zi, clusterId: cr, accountId: ir, streamName: or, subscriberId: ar, connection: rs, stats: ur.slice(-t), connectionDurationMs: (/* @__PURE__ */ new Date()).getTime() - lr }; return At !== "" ? s.feedId = At : Tt !== "" && (s.streamViewId = Tt), e === "CMCD" ? Ki(s) : s; } }; ct.useDefaults({ defaultLevel: ct.TRACE }); const dr = ["TRACE", "DEBUG", "INFO", "WARN", "ERROR"], Fs = (r, e) => { r.unshift("[".concat(e.name || "Global", "] ").concat((/* @__PURE__ */ new Date()).toISOString(), " - ").concat(e.level.name, " -")); }, Vs = (r, e) => e ? r.value >= rt[e].value : r.value >= hr.value, Hi = (r, e) => { r = Array.prototype.slice.call(r), r = r.map((t) => typeof t == "object" ? JSON.stringify(t) : t), Fs(r, e), Nt !== 0 ? (vt.push(r.join(" ")), vt.length >= Nt && (vt = vt.slice(-Nt))) : vt = []; }, Ji = ct.createDefaultHandler({ formatter: Fs }); ct.setHandler((r, e) => { Hi(r, e), Vs(e.level, e.name) && Ji(r, e); for (const { handler: t, level: s } of Ns) e.level.value >= s.value && t(r, e); }); const Qi = 1e4; let Nt = Qi, vt = [], hr = ct.OFF; const rt = {}, Ns = [], Be = ke(J({}, ct), { enabledFor: Vs, /** * @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: () => vt, /** * @function * @name getHistoryMaxSize * @description Get the maximum count of logs preserved during a session. * @example Logger.getHistoryMaxSize() */ getHistoryMaxSize: () => Nt, /** * @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: (r) => { Nt = r; }, /** * @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: (r) => { hr = r; for (const e in rt) rt[e] = r; }, /** * @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: () => hr, /** * @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: (r) => { rt[r] || (rt[r] = hr); const e = ct.get(r); return e.setLevel = (t) => { rt[r] = t; }, e.getLevel = () => rt[r], 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: (r, e) => { Ns.push({ handler: r, 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: (r = {}) => { let e; const t = { statsCount: 60, historySize: 1e3, minLogLevel: "TRACE", statsFormat: "JSON" }; typeof r == "number" ? (t.statsCount = r, e = t) : e = J(J({}, t), r); const { statsCount: s, historySize: d, minLogLevel: p, statsFormat: f } = e, n = Ee.get(s, f), b = Be.getHistory(); if (!Number.isInteger(d) || d <= 0) throw new Error("Invalid Argument Exception : historySize must be a positive integer."); if (!dr.includes(p.toUpperCase())) throw new Error('Invalid Argument Exception : the minLogLevel parameter only excepts "trace", "debug", "info", "warn", and "error" as arguments.'); if (dr.includes(p.toUpperCase())) { const y = dr.slice(dr.indexOf(p.toUpperCase())), h = b.filter((a) => y.some((c) => a.includes(c))); n.history = h.slice(-d); } return n; }, JSON: "JSON", CMCD: "CMCD", /** * @var * @name VERSION * @description Returns the current SDK version. */ VERSION: Zs }); var hn = { exports: {} }, xt = typeof Reflect == "object" ? Reflect : null, ns = xt && typeof xt.apply == "function" ? xt.apply : function(e, t, s) { return Function.prototype.apply.call(e, t, s); }, pr; xt && typeof xt.ownKeys == "function" ? pr = xt.ownKeys : Object.getOwnPropertySymbols ? pr = function(e) { return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e)); } : pr = function(e) { return Object.getOwnPropertyNames(e); }; function qi(r) { console && console.warn && console.warn(r); } var Os = Number.isNaN || function(e) { return e !== e; }; function ne() { ne.init.call(this); } hn.exports = ne; hn.exports.once = no; ne.EventEmitter = ne; ne.prototype._events = void 0; ne.prototype._eventsCount = 0; ne.prototype._maxListeners = void 0; var ss = 10; function kr(r) { if (typeof r != "function") throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof r); } Object.defineProperty(ne, "defaultMaxListeners", { enumerable: !0, get: function() { return ss; }, set: function(r) { if (typeof r != "number" || r < 0 || Os(r)) throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + r + "."); ss = r; } }); ne.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; }; ne.prototype.setMaxListeners = function(e) { if (typeof e != "number" || e < 0 || Os(e)) throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + e + "."); return this._maxListeners = e, this; }; function Us(r) { return r._maxListeners === void 0 ? ne.defaultMaxListeners : r._maxListeners; } ne.prototype.getMaxListeners = function() { return Us(this); }; ne.prototype.emit = function(e) { for (var t = [], s = 1; s < arguments.length; s++) t.push(arguments[s]); var d = e === "error", p = this._events; if (p !== void 0) d = d && p.error === void 0; else if (!d) return !1; if (d) { var f; if (t.length > 0 && (f = t[0]), f instanceof Error) throw f; var n = new Error("Unhandled error." + (f ? " (" + f.message + ")" : "")); throw n.context = f, n; } var b = p[e]; if (b === void 0) return !1; if (typeof b == "function") ns(b, this, t); else for (var y = b.length, h = Bs(b, y), s = 0; s < y; ++s) ns(h[s], this, t); return !0; }; function Ps(r, e, t, s) { var d, p, f; if (kr(t), p = r._events, p === void 0 ? (p = r._events = /* @__PURE__ */ Object.create(null), r._eventsCount = 0) : (p.newListener !== void 0 && (r.emit( "newListener", e, t.listener ? t.listener : t ), p = r._events), f = p[e]), f === void 0) f = p[e] = t, ++r._eventsCount; else if (typeof f == "function" ? f = p[e] = s ? [t, f] : [f, t] : s ? f.unshift(t) : f.push(t), d = Us(r), d > 0 && f.length > d && !f.warned) { f.warned = !0; var n = new Error("Possible EventEmitter memory leak detected. " + f.length + " " + String(e) + " listeners added. Use emitter.setMaxListeners() to increase limit"); n.name = "MaxListenersExceededWarning", n.emitter = r, n.type = e, n.count = f.length, qi(n); } return r; } ne.prototype.addListener = function(e, t) { return Ps(this, e, t, !1); }; ne.prototype.on = ne.prototype.addListener; ne.prototype.prependListener = function(e, t) { return Ps(this, e, t, !0); }; function eo() { 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 js(r, e, t) { var s = { fired: !1, wrapFn: void 0, target: r, type: e, listener: t }, d = eo.bind(s); return d.listener = t, s.wrapFn = d, d; } ne.prototype.once = function(e, t) { return kr(t), this.on(e, js(this, e, t)), this; }; ne.prototype.prependOnceListener = function(e, t) { return kr(t), this.prependListener(e, js(this, e, t)), this; }; ne.prototype.removeListener = function(e, t) { var s, d, p, f, n; if (kr(t), d = this._events, d === void 0) return this; if (s = d[e], s === void 0) return this; if (s === t || s.listener === t) --this._eventsCount === 0 ? this._events = /* @__PURE__ */ Object.create(null) : (delete d[e], d.removeListener && this.emit("removeListener", e, s.listener || t)); else if (typeof s != "function") { for (p = -1, f = s.length - 1; f >= 0; f--) if (s[f] === t || s[f].listener === t) { n = s[f].listener, p = f; break; } if (p < 0) return this; p === 0 ? s.shift() : to(s, p), s.length === 1 && (d[e] = s[0]), d.removeListener !== void 0 && this.emit("removeListener", e, n || t); } return this; }; ne.prototype.off = ne.prototype.removeListener; ne.prototype.removeAllListeners = function(e) { var t, s, d; if (s = this._events, s === void 0) return this; if (s.removeListener === void 0) return arguments.length === 0 ? (this._events = /* @__PURE__ */ Object.create(null), this._eventsCount = 0) : s[e] !== void 0 && (--this._eventsCount === 0 ? this._events = /* @__PURE__ */ Object.create(null) : delete s[e]), this; if (arguments.length === 0) { var p = Object.keys(s), f; for (d = 0; d < p.length; ++d) f = p[d], f !== "removeListener" && this.removeAllListeners(f); return this.removeAllListeners("removeListener"), this._events = /* @__PURE__ */ Object.create(null), this._eventsCount = 0, this; } if (t = s[e], typeof t == "function") this.removeListener(e, t); else if (t !== void 0) for (d = t.length - 1; d >= 0; d--) this.removeListener(e, t[d]); return this; }; function $s(r, e, t) { var s = r._events; if (s === void 0) return []; var d = s[e]; return d === void 0 ? [] : typeof d == "function" ? t ? [d.listener || d] : [d] : t ? ro(d) : Bs(d, d.length); } ne.prototype.listeners = function(e) { return $s(this, e, !0); }; ne.prototype.rawListeners = function(e) { return $s(this, e, !1); }; ne.listenerCount = function(r, e) { return typeof r.listenerCount == "function" ? r.listenerCount(e) : Ws.call(r, e); }; ne.prototype.listenerCount = Ws; function Ws(r) { var e = this._events; if (e !== void 0) { var t = e[r]; if (typeof t == "function") return 1; if (t !== void 0) return t.length; } return 0; } ne.prototype.eventNames = function() { return this._eventsCount > 0 ? pr(this._events) : []; }; function Bs(r, e) { for (var t = new Array(e), s = 0; s < e; ++s) t[s] = r[s]; return t; } function to(r, e) { for (; e + 1 < r.length; e++) r[e] = r[e + 1]; r.pop(); } function ro(r) { for (var e = new Array(r.length), t = 0; t < e.length; ++t) e[t] = r[t].listener || r[t]; return e; } function no(r, e) { return new Promise(function(t, s) { function d(f) { r.removeListener(e, p), s(f); } function p() { typeof r.removeListener == "function" && r.removeListener("error", d), t([].slice.call(arguments)); } Gs(r, e, p, { once: !0 }), e !== "error" && so(r, d, { once: !0 }); }); } function so(r, e, t) { typeof r.on == "function" && Gs(r, "error", e, t); } function Gs(r, e, t, s) { if (typeof r.on == "function") s.once ? r.once(e, t) : r.on(e, t); else if (typeof r.addEventListener == "function") r.addEventListener(e, function d(p) { s.once && r.removeEventListener(e, d), t(p); }); else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof r); } var pn = hn.exports; const Cr = /* @__PURE__ */ Et(pn); var mn = { exports: {} }; mn.exports = Xs; mn.exports.filter = oo; var io = pn.EventEmitter; function Xs(r, e, t) { Array.isArray(t) || (t = [t]); var s = []; return t.forEach(function(d) { var p = function() { var f = [].slice.call(arguments); f.unshift(d), e.emit.apply(e, f); }; s.push(p), r.on(d, p); }), function() { t.forEach(function(p, f) { r.removeListener(p, s[f]); }); }; } function oo(r, e) { var t = new io(); return Xs(r, t, e), t; } var ao = mn.exports; const vr = /* @__PURE__ */ Et(ao); var Ys = { exports: {} }; /*! For license information please see webrtc-stats.js.LICENSE.txt */ (function(r, e) { (function(t, s) { r.exports = s(); })(self, () => { return t = { 7: (d) => { var p, f = typeof Reflect == "object" ? Reflect : null, n = f && typeof f.apply == "function" ? f.apply : function(S, R, E) { return Function.prototype.apply.call(S, R, E); }; p = f && typeof f.ownKeys == "function" ? f.ownKeys : Object.getOwnPropertySymbols ? function(S) { return Object.getOwnPropertyNames(S).concat(Object.getOwnPropertySymbols(S)); } : function(S) { return Object.getOwnPropertyNames(S); }; var b = Number.isNaN || function(S) { return S != S; }; function y() { y.init.call(this); } d.exports = y, d.exports.once = function(S, R) { return new Promise(function(E, T) { function x(_) { S.removeListener(R, k), T(_); } function k() { typeof S.removeListener == "function" && S.removeListener("error", x), E([].slice.call(arguments)); } w(S, R, k, { once: !0 }), R !== "error" && function(_, M) { typeof _.on == "function" && w(_, "error", M, { once: !0 }); }(S, x); }); }, y.EventEmitter = y, y.prototype._events = void 0, y.prototype._eventsCount = 0, y.prototype._maxListeners = void 0; var h = 10; function a(S) { if (typeof S != "function") throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof S); } function c(S) { return S._maxListeners === void 0 ? y.defaultMaxListeners : S._maxListeners; } function l(S, R, E, T) { var x, k, _, M; if (a(E), (k = S._events) === void 0 ? (k = S._events = /* @__PURE__ */ Object.create(null), S._eventsCount = 0) : (k.newListener !== void 0 && (S.emit("newListener", R, E.listener ? E.listener : E), k = S._events), _ = k[R]), _ === void 0) _ = k[R] = E, ++S._eventsCount; else if (typeof _ == "function" ? _ = k[R] = T ? [E, _] : [_, E] : T ? _.unshift(E) : _.push(E), (x = c(S)) > 0 && _.length > x && !_.warned) { _.warned = !0; var O = new Error("Possible EventEmitter memory leak detected. " + _.length + " " + String(R) + " listeners added. Use emitter.setMaxListeners() to increase limit"); O.name = "MaxListenersExceededWarning", O.emitter = S, O.type = R, O.count = _.length, M = O, console && console.warn && console.warn(M); } return S; } function i() { 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 o(S, R, E) { var T = { fired: !1, wrapFn: void 0, target: S, type: R, listener: E }, x = i.bind(T); return x.listener = E, T.wrapFn = x, x; } function m(S, R, E) { var T = S._events; if (T === void 0) return []; var x = T[R]; return x === void 0 ? [] : typeof x == "function" ? E ? [x.listener || x] : [x] : E ? function(k) { for (var _ = new Array(k.length), M = 0; M < _.length; ++M) _[M] = k[M].listener || k[M]; return _; }(x) : g(x, x.length); } function u(S) { var R = this._events; if (R !== void 0) { var E = R[S]; if (typeof E == "function") return 1; if (E !== void 0) return E.length; } return 0; } function g(S, R) { for (var E = new Array(R), T = 0; T < R; ++T) E[T] = S[T]; return E; } function w(S, R, E, T) { if (typeof S.on == "function") T.once ? S.once(R, E) : S.on(R, E); else { if (typeof S.addEventListener != "function") throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof S); S.addEventListener(R, function x(k) { T.once && S.removeEventListener(R, x), E(k); }); } } Object.defineProperty(y, "defaultMaxListeners", { enumerable: !0, get: function() { return h; }, set: function(S) { if (typeof S != "number" || S < 0 || b(S)) throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + S + "."); h = S; } }), y.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; }, y.prototype.setMaxListeners = function(S) { if (typeof S != "number" || S < 0 || b(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; }, y.prototype.getMaxListeners = function() { return c(this); }, y.prototype.emit = function(S) { for (var R = [], E = 1; E < arguments.length; E++) R.push(arguments[E]); var T = S === "error", x = this._events; if (x !== void 0) T = T && x.error === void 0; else if (!T) return !1; if (T) { var k; if (R.length > 0 && (k = R[0]), k instanceof Error) throw k; var _ = new Error("Unhandled error." + (k ? " (" + k.message + ")" : "")); throw _.context = k, _; } var M = x[S]; if (M === void 0) return !1; if (typeof M == "function") n(M, this, R); else { var O = M.length, U = g(M, O); for (E = 0; E < O; ++E) n(U[E], this, R); } return !0; }, y.prototype.addListener = function(S, R) { return l(this, S, R, !1); }, y.prototype.on = y.prototype.addListener, y.prototype.prependListener = function(S, R) { return l(this, S, R, !0); }, y.prototype.once = function(S, R) { return a(R), this.on(S, o(this, S, R)), this; }, y.prototype.prependOnceListener = function(S, R) { return a(R), this.prependListener(S, o(this, S, R)), this; }, y.prototype.removeListener = function(S, R) { var E, T, x, k, _; if (a(R), (T = this._events) === void 0) return this; if ((E = T[S]) === void 0) return this; if (E === R || E.listener === R) --this._eventsCount == 0 ? this._events = /* @__PURE__ */ Object.create(null) : (delete T[S], T.removeListener && this.emit("removeListener", S, E.listener || R)); else if (typeof E != "function") { for (x = -1, k = E.length - 1; k >= 0; k--) if (E[k] === R || E[k].listener === R) { _ = E[k].listener, x = k; break; } if (x < 0) return this; x === 0 ? E.shift() : function(M, O) { for (; O + 1 < M.length; O++) M[O] = M[O + 1]; M.pop(); }(E, x), E.length === 1 && (T[S] = E[0]), T.removeListener !== void 0 && this.emit("removeListener", S, _ || R); } return this; }, y.prototype.off = y.prototype.removeListener, y.prototype.removeAllListeners = function(S) { var R, E, T; 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[S] !== void 0 && (--this._eventsCount == 0 ? this._events = /* @__PURE__ */ Object.create(null) : delete E[S]), this; if (arguments.length === 0) { var x, k = Object.keys(E); for (T = 0; T < k.length; ++T) (x = k[T]) !== "removeListener" && this.removeAllListeners(x); return this.removeAllListeners("removeListener"), this._events = /* @__PURE__ */ Object.create(null), this._eventsCount = 0, this; } if (typeof (R = E[S]) == "function") this.removeListener(S, R); else if (R !== void 0) for (T = R.length - 1; T >= 0; T--) this.removeListener(S, R[T]); return this; }, y.prototype.listeners = function(S) { return m(this, S, !0); }, y.prototype.rawListeners = function(S) { return m(this, S, !1); }, y.listenerCount = function(S, R) { return typeof S.listenerCount == "function" ? S.listenerCount(R) : u.call(S, R); }, y.prototype.listenerCount = u, y.prototype.eventNames = function() { return this._eventsCount > 0 ? p(this._events) : []; }; }, 156: function(d, p, f) { var n = this && this.__createBinding || (Object.create ? function(a, c, l, i) { i === void 0 && (i = l); var o = Object.getOwnPropertyDescriptor(c, l); o && !("get" in o ? !c.__esModule : o.writable || o.configurable) || (o = { enumerable: !0, get: function() { return c[l]; } }), Object.defineProperty(a, i, o); } : function(a, c, l, i) { i === void 0 && (i = l), a[i] = c[l]; }), b = this && this.__exportStar || function(a, c) { for (var l in a) l === "default" || Object.prototype.hasOwnProperty.call(c, l) || n(c, a, l); }, y = this && this.__importDefault || function(a) { return a && a.__esModule ? a : { default: a }; }; Object.defineProperty(p, "__esModule", { value: !0 }), p.Logger = void 0; var h = f(586); Object.defineProperty(p, "Logger", { enumerable: !0, get: function() { return y(h).default; } }), b(f(284), p), b(f(280), p), b(f(738), p), b(f(767), p); }, 185: (d, p) => { Object.defineProperty(p, "__esModule", { value: !0 }), p.calculatePacketsLostRatio = p.calculateRate = p.getMediaKind = void 0, p.getMediaKind = (f) => { let n = f.kind || f.mediaType; return ["audio", "video"].includes(n) || f.type !== "inbound-rtp" || (n = f.id.toLocaleLowerCase().includes("video") ? "video" : "audio"), n; }, p.calculateRate = (f, n, b, y) => b && y ? (n - y) / ((f - b) / 1e3) : 0, p.calculatePacketsLostRatio = (f, n, b, y) => { const h = f - (b != null ? b : 0), a = h + (n - (y != null ? y : 0)); return a === 0 ? 0 : h / a; }; }, 280: (d, p) => { Object.defineProperty(p, "__esModule", { value: !0 }); }, 284: function(d, p, f) { var n, b, y, h, a, c, l, i, o, m, u, g, w, S, R, E, T = this && this.__awaiter || function(W, N, P, Y) { return new (P || (P = Promise))(function(G, B) { function z(re) { try { te(Y.next(re)); } catch (fe) { B(fe); } } function q(re) { try { te(Y.throw(re)); } catch (fe) { B(fe); } } function te(re) { var fe; re.done ? G(re.value) : (fe = re.value, fe instanceof P ? fe : new P(function(ve) { ve(fe); })).then(z, q); } te((Y = Y.apply(W, N || [])).next()); }); }, x = this && this.__classPrivateFieldSet || function(W, N, P, Y, G) { if (Y === "m") throw new TypeError("Private method is not writable"); if (Y === "a" && !G) throw new TypeError("Private accessor was defined without a setter"); if (typeof N == "function" ? W !== N || !G : !N.has(W)) throw new TypeError("Cannot write private member to an object whose class did not declare it"); return Y === "a" ? G.call(W, P) : G ? G.value = P : N.set(W, P), P; }, k = this && this.__classPrivateFieldGet || function(W, N, P, Y) { if (P === "a" && !Y) throw new TypeError("Private accessor was defined without a getter"); if (typeof N == "function" ? W !== N || !Y : !N.has(W)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return P === "m" ? Y : P === "a" ? Y.call(W) : Y ? Y.value : N.get(W); }, _ = this && this.__importDefault || function(W) { return W && W.__esModule ? W : { default: W }; }; Object.defineProperty(p, "__esModule", { value: !0 }), p.WebRTCStats = void 0; const M = f(7), O = _(f(586)), U = f(738), j = f(185); class X extends M.EventEmitter { constructor(N) { super(), n.add(this), b.set(this, void 0), y.set(this, void 0), h.set(this, void 0), a.set(this, null), c.set(this, void 0), l.set(this, null), this.start = () => { k(this, c, "f").info("WebRTC statistics collection is starting..."), x(this, l, null, "f"), x(this, a, setInterval(k(this, i, "f"), k(this, y, "f")), "f"); }, this.stop = () => { k(this, a, "f") && (clearInterval(k(this, a, "f")), x(this, a, null, "f"), k(this, c, "f").info("WebRTC statistics collection has stopped.")); }, i.set(this, () => T(this, void 0, void 0, function* () { let P, Y; try { k(this, c, "f").trace("Requesting WebRTC statistics..."), P = yield k(this, b, "f").call(this), Y = (/* @__PURE__ */ new Date()).toISOString(); } catch (z) { return k(this, c, "f").error("Problem collecting the WebRTC statistics.", z), void this.emit("error", "Problem collecting the WebRTC statistics - ".concat(z)); } const G = Array.from(P.values()), B = { timestamp: Y, input: { audio: [], video: [] }, output: { audio: [], video: [] } }; k(this, h, "f") && (B.rawStats = P); for (let z = 0; z < Object.keys(G).length; z++) { const q = G[z]; switch (q.type) { case "outbound-rtp": const te = q, re = (0, j.getMediaKind)(te); re === "audio" ? yield k(this, n, "m", u).call(this, P, te, B) : re === "video" && (yield k(this, n, "m", g).call(this, P, te, B)); break; case "inbound-rtp": const fe = q; let ve = (0, j.getMediaKind)(fe); ve === "audio" ? yield k(this, n, "m", S).call(this, P, fe, B) : ve === "video" && (yield k(this, n, "m", R).call(this, P, fe, B)); break; case "candidate-pair": const De = q; De.nominated && k(this, n, "m", E).call(this, De, B); } } x(this, l, B, "f"), this.emit("stats", B); })), x(this, c, O.default.get("WebRTCStats"), "f"), x(this, b, N.getStats, "f"), x(this, y, N.getStatsInterval || 1e3, "f"), x(this, h, !!N.includeRawStats, "f"); } } p.WebRTCStats = X, b = /* @__PURE__ */ new WeakMap(), y = /* @__PURE__ */ new WeakMap(), h = /* @__PURE__ */ new WeakMap(), a = /* @__PURE__ */ new WeakMap(), c = /* @__PURE__ */ new WeakMap(), l = /* @__PURE__ */ new WeakMap(), i = /* @__PURE__ */ new WeakMap(), n = /* @__PURE__ */ new WeakSet(), o = function(W, N) { if (N) { const P = W.get(N); if (P) return { mimeType: P.mimeType }; } return {}; }, m = function(W, N, P) { return T(this, void 0, void 0, function* () { var Y, G, B, z; const q = (0, j.calculateRate)(N.timestamp, N.bytesSent, P == null ? void 0 : P.timestamp, P == null ? void 0 : P.totalBytesSent), te = (0, j.calculateRate)(N.timestamp, N.packetsSent, P == null ? void 0 : P.timestamp, P == null ? void 0 : P.totalPacketsSent), re = k(this, n, "m", o).call(this, W, N.codecId); return Object.assign({ id: N.id, timestamp: N.timestamp, mid: N.mid, totalBytesSent: N.bytesSent, bytesSentDelta: N.bytesSent - ((Y = P == null ? void 0 : P.totalBytesSent) !== null && Y !== void 0 ? Y : 0), totalPacketsSent: N.packetsSent, packetsSentDelta: N.packetsSent - ((G = P == null ? void 0 : P.totalPacketsSent) !== null && G !== void 0 ? G : 0), bitrate: q, packetRate: te, targetBitrate: N.targetBitrate, retransmittedPacketsSent: N.retransmittedPacketsSent, retransmittedPacketsSentDelta: N.retransmittedPacketsSent - ((B = P == null ? void 0 : P.retransmittedPacketsSent) !== null && B !== void 0 ? B : 0), retransmittedBytesSent: N.retransmittedBytesSent, retransmittedBytesSentDelta: N.retransmittedBytesSent - ((z = P == null ? void 0 : P.retransmittedBytesSent) !== null && z !== void 0 ? z : 0) }, re); }); }, u = function(W, N, P) { return T(this, void 0, void 0, function* () { var Y; const G = (Y = k(this, l, "f")) === null || Y === void 0 ? void 0 : Y.output.audio.find((q) => q.id === N.id); if (G && N.timestamp - G.timestamp <= 0) return; const B = yield k(this, n, "m", m).call(this, W, N, G), z = Object.assign({}, B); P.output.audio.push(z); }); }, g = function(W, N, P) { return T(this, void 0, void 0, function* () { var Y; const G = (Y = k(this, l, "f")) === null || Y === void 0 ? void 0 : Y.output.video.find((te) => te.id === N.id); if (G && N.timestamp - G.timestamp <= 0) return; const B = yield k(this, n, "m", m).call(this, W, N, G); let z = U.QualityLimitationReason.none; N.qualityLimitationReason && (z = N.qualityLimitationReason); const q = Object.assign(Object.assign({}, B), { frameWidth: N.frameWidth, frameHeight: N.frameHeight, framesPerSecond: N.framesPerSecond, framesSent: N.framesSent, qualityLimitationReason: z, qualityLimitationDurations: N.qualityLimitationDurations }); P.output.video.push(q); }); }, w = function(W, N, P) { return T(this, void 0, void 0, function* () { var Y, G; const B = (0, j.calculateRate)(N.timestamp, N.bytesReceived, P == null ? void 0 : P.timestamp, P == null ? void 0 : P.totalBytesReceived), z = (0, j.calculateRate)(N.timestamp, N.packetsReceived, P == null ? void 0 : P.timestamp, P == null ? void 0 : P.totalPacketsReceived), q = (0, j.calculatePacketsLostRatio)(N.packetsLost, N.packetsReceived, P == null ? void 0 : P.totalPacketsLost, P == null ? void 0 : P.totalPacketsReceived), te = ((Y = N.packetsLost) !== null && Y !== void 0 ? Y : 0) - ((G = P == null ? void 0 : P.totalPacketsLost) !== null && G !== void 0 ? G : 0), re = k(this, n, "m", o).call(this, W, N.codecId); return Object.assign({ id: N.id, timestamp: N.timestamp, mid: N.mid, trackIdentifier: N.trackIdentifier, jitter: N.jitter, jitterBufferDelay: N.jitterBufferDelay, jitterBufferEmittedCount: N.jitterBufferEmittedCount, totalBytesReceived: N.bytesReceived, totalPacketsReceived: N.packetsReceived, totalPacketsLost: N.packetsLost, bitrate: B, packetRate: z, packetLossRatio: q, packetLossDelta: te }, re); }); }, S = function(W, N, P) { return T(this, void 0, void 0, function* () { var Y; const G = (Y = k(this, l, "f")) === null || Y === void 0 ? void 0 : Y.input.audio.find((z) => z.id === N.id); if (G && N.timestamp - G.timestamp <= 0) return; const B = yield k(this, n, "m", w).call(this, W, N, G); P.input.audio.push(B); }); }, R = function(W, N, P) { return T(this, void 0, void 0, function* () { var Y; const G = (Y = k(this, l, "f")) === null || Y === void 0 ? void 0 : Y.input.video.find((q) => q.id === N.id); if (G && N.timestamp - G.timestamp <= 0) return; const B = yield k(this, n, "m", w).call(this, W, N, G), z = Object.assign(Object.assign({}, B), { keyFramesDecoded: N.keyFramesDecoded, frameHeight: N.frameHeight, frameWidth: N.frameWidth, framesDecoded: N.framesDecoded, framesDropped: N.framesDropped, framesPerSecond: N.framesPerSecond, framesReceived: N.framesReceived }); P.input.video.push(z); }); }, E = function(W, N) { N.totalRoundTripTime = W.totalRoundTripTime, N.currentRoundTripTime = W.currentRoundTripTime, N.responsesReceived = W.responsesReceived, N.availableOutgoingBitrate = W.availableOutgoingBitrate, N.availableIncomingBitrate = W.availableIncomingBitrate; }; }, 586: function(d, p, f) { var n, b; (function() { var y, h = { VERSION: "1.6.1" }, a = {}, c = function(g, w) { return function() { return w.apply(g, arguments); }; }, l = function() { var g, w, S = arguments, R = S[0]; for (w = 1; w < S.length; w++) for (g in S[w]) !(g in R) && S[w].hasOwnProperty(g) && (R[g] = S[w][g]); return R; }, i = function(g, w) { return { value: g, name: w }; }; h.TRACE = i(1, "TRACE"), h.DEBUG = i(2, "DEBUG"), h.INFO = i(3, "INFO"), h.TIME = i(4, "TIME"), h.WARN = i(5, "WARN"), h.ERROR = i(8, "ERROR"), h.OFF = i(99, "OFF"); var o = function(g) { this.context = g, this.setLevel(g.filterLevel), this.log = this.info; }; o.prototype = { setLevel: function(g) { g && "value" in g && (this.context.filterLevel = g); }, getLevel: function() { return this.context.filterLevel; }, enabledFor: function(g) { var w = this.context.filterLevel; return g.value >= w.value; }, trace: function() { this.invoke(h.TRACE, arguments); }, debug: function() { this.invoke(h.DEBUG, arguments); }, info: function() { this.invoke(h.INFO, arguments); }, warn: function() { this.invoke(h.WARN, arguments); }, error: function() { this.invoke(h.ERROR, arguments); }, time: function(g) { typeof g == "string" && g.length > 0 && this.invoke(h.TIME, [g, "start"]); }, timeEnd: function(g) { typeof g == "string" && g.length > 0 && this.invoke(h.TIME, [g, "end"]); }, invoke: function(g, w) { y && this.enabledFor(g) && y(w, l({ level: g }, this.context)); } }; var m, u = new o({ filterLevel: h.OFF }); (m = h).enabledFor = c(u, u.enabledFor), m.trace = c(u, u.trace), m.debug = c(u, u.debug), m.time = c(u, u.time), m.timeEnd = c(u, u.timeEnd), m.info = c(u, u.info), m.warn = c(u, u.warn), m.error = c(u, u.error), m.log = m.info, h.setHandler = function(g) { y = g; }, h.setLevel = function(g) { for (var w in u.setLevel(g), a) a.hasOwnProperty(w) && a[w].setLevel(g); }, h.getLevel = function() { return u.getLevel(); }, h.get = function(g) { return a[g] || (a[g] = new o(l({ name: g }, u.context))); }, h.createDefaultHandler = function(g) { (g = g || {}).formatter = g.formatter || function(R, E) { E.name && R.unshift("[" + E.name + "]"); }; var w = {}, S = function(R, E) { Function.prototype.apply.call(R, console, E); }; return typeof console > "u" ? function() { } : function(R, E) { R = Array.prototype.slice.call(R); var T, x = console.log; E.level === h.TIME ? (T = (E.name ? "[" + E.name + "] " : "") + R[0], R[1] === "start" ? console.time ? console.time(T) : w[T] = (/* @__PURE__ */ new Date()).getTime() : console.timeEnd ? console.timeEnd(T) : S(x, [T + ": " + ((/* @__PURE__ */ new Date()).getTime() - w[T]) + "ms"])) : (E.level === h.WARN && console.warn ? x = console.warn : E.level === h.ERROR && console.error ? x = console.error : E.level === h.INFO && console.info ? x = console.info : E.level === h.DEBUG && console.debug ? x = console.debug : E.level === h.TRACE && console.trace && (x = console.trace), g.formatter(R, E), S(x, R)); }; }, h.useDefaults = function(g) { h.setLevel(g && g.defaultLevel || h.DEBUG), h.setHandler(h.createDefaultHandler(g)); }, h.setDefaults = h.useDefaults, (b = typeof (n = h) == "function" ? n.call(p, f, p, d) : n) === void 0 || (d.exports = b); })(); }, 738: (d, p) => { var f; Object.defineProperty(p, "__esModule", { value: !0 }), p.QualityLimitationReason = void 0, function(n) { n[n.none = 0] = "none", n[n.cpu = 1] = "cpu", n[n.bandwidth = 2] = "bandwidth", n[n.other = 3] = "other"; }(f || (p.QualityLimitationReason = f = {})); }, 767: (d, p) => { Object.defineProperty(p, "__esModule", { value: !0 }); } }, s = {}, function d(p) { var f = s[p]; if (f !== void 0) return f.exports; var n = s[p] = { exports: {} }; return t[p].call(n.exports, n, n.exports, d), n.exports; }(156); var t, s; }); })(Ys); var co = Ys.exports; const Mt = Be.get("PeerConnectionStats"), zs = { stats: "stats" }, lo = (r) => { const f = r, { input: e, output: t, rawStats: s } = f, d = tt(f, ["input", "output", "rawStats"]); return ke(J({}, d), { audio: { inbounds: r.input.audio.map((a) => { var c = a, { packetLossRatio: n, packetLossDelta: b, bitrate: y } = c, h = tt(c, ["packetLossRatio", "packetLossDelta", "bitrate"]); return J({ packetsLostRatioPerSecond: n, packetsLostDeltaPerSecond: b, bitrateBitsPerSecond: y * 8, bitrate: y }, h); }), outbounds: r.output.audio.map((a) => { var c = a, { packetLossRatio: n, packetLossDelta: b, bitrate: y } = c, h = tt(c, ["packetLossRatio", "packetLossDelta", "bitrate"]); return J({ packetsLostRatioPerSecond: n, packetsLostDeltaPerSecond: b, bitrateBitsPerSecond: y * 8, bitrate: y }, h); }) }, video: { inbounds: r.input.video.map((a) => { var c = a, { packetLossRatio: n, packetLossDelta: b, bitrate: y } = c, h = tt(c, ["packetLossRatio", "packetLossDelta", "bitrate"]); return J({ packetsLostRatioPerSecond: n, packetsLostDeltaPerSecond: b, bitrateBitsPerSecond: y * 8, bitrate: y }, h); }), outbounds: r.output.video.map((a) => { var c = a, { packetLossRatio: n, packetLossDelta: b, bitrate: y } = c, h = tt(c, ["packetLossRatio", "packetLossDelta", "bitrate"]); return J({ packetsLostRatioPerSecond: n, packetsLostDeltaPerSecond: b, bitrateBitsPerSecond: y * 8, bitrate: y }, h); }) }, raw: r