UNPKG

@vonage/ml-transformers

Version:

<!-- README for NPM; the one for GitHub is in .github directory. -->

1,371 lines 321 kB
function sn(r, e) { globalThis.vonage || (globalThis.vonage = {}), globalThis.vonage.workerizer || (globalThis.vonage.workerizer = {}); let t = globalThis.vonage.workerizer; return t[r] || (t[r] = e), t[r]; } const je = sn( "globals", {} ); var U = /* @__PURE__ */ ((r) => (r.INIT = "INIT", r.FORWARD = "FORWARD", r.TERMINATE = "TERMINATE", r.GLOBALS_SYNC = "GLOBALS_SYNC", r.EVENT = "EVENT", r))(U || {}); function Ci(r) { return [ImageBitmap, ReadableStream, WritableStream].some((e) => r instanceof e); } let Ls = 0; function Nt(r, e, t, n, i) { const o = Ls++; return r.postMessage( { id: o, type: e, functionName: t, args: n }, n.filter((s) => Ci(s)) ), new Promise((s) => { i?.set(o, s); }); } function Ve(r, e) { const { id: t, type: n } = r, i = Array.isArray(e) ? e : [e]; postMessage( { id: t, type: n, result: e }, i.filter((o) => Ci(o)) ); } const $t = sn("workerized", {}); function an() { return typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope; } async function zs() { if (an()) Ve({ type: U.GLOBALS_SYNC }, je); else { const r = []; for (const e in $t) { const { worker: t, resolvers: n } = $t[e].workerContext; t && r.push( Nt( t, U.GLOBALS_SYNC, "", [je], n ) ); } await Promise.all(r); } } function ot(r, e) { if (Array.isArray(e)) e.splice(0, e.length); else if (typeof e == "object") for (const t in e) delete e[t]; for (const t in r) Array.isArray(r[t]) ? (e[t] = [], ot(r[t], e[t])) : typeof r[t] == "object" ? (e[t] = {}, ot(r[t], e[t])) : e[t] = r[t]; } async function Us(r, e, t, n) { const i = new e(); if (i.addEventListener( "message", async ({ data: o }) => { var s, a, c, u, f, h, p; switch (o.type) { case U.GLOBALS_SYNC: o.id ? ((a = t.get((s = o.id) != null ? s : -1)) == null || a(o.result), t.delete((c = o.id) != null ? c : -1)) : (ot((u = o.result) != null ? u : {}, je), await zs()); break; case U.EVENT: const { result: g } = o, d = g; if (d?.name == null) throw "Missing event name"; n(d.name, d.data); break; default: (h = t.get((f = o.id) != null ? f : -1)) == null || h(o.result), t.delete((p = o.id) != null ? p : -1); } } ), !await Nt( i, U.INIT, "", [r.workerId, je], t )) throw "Failed to instantiate workerized class"; return i; } const te = /* @__PURE__ */ new WeakMap(), ge = /* @__PURE__ */ new WeakMap(), X = /* @__PURE__ */ new WeakMap(), Wt = /* @__PURE__ */ Symbol("anyProducer"), Qn = Promise.resolve(), Gt = /* @__PURE__ */ Symbol("listenerAdded"), jt = /* @__PURE__ */ Symbol("listenerRemoved"); let Vt = !1, Mr = !1; function ke(r) { if (typeof r != "string" && typeof r != "symbol" && typeof r != "number") throw new TypeError("`eventName` must be a string, symbol, or number"); } function Et(r) { if (typeof r != "function") throw new TypeError("listener must be a function"); } function Re(r, e) { const t = ge.get(r); if (t.has(e)) return t.get(e); } function tt(r, e) { const t = typeof e == "string" || typeof e == "symbol" || typeof e == "number" ? e : Wt, n = X.get(r); if (n.has(t)) return n.get(t); } function Ns(r, e, t) { const n = X.get(r); if (n.has(e)) for (const i of n.get(e)) i.enqueue(t); if (n.has(Wt)) { const i = Promise.all([e, t]); for (const o of n.get(Wt)) o.enqueue(i); } } function Xn(r, e) { e = Array.isArray(e) ? e : [e]; let t = !1, n = () => { }, i = []; const o = { enqueue(s) { i.push(s), n(); }, finish() { t = !0, n(); } }; for (const s of e) { let a = tt(r, s); a || (a = /* @__PURE__ */ new Set(), X.get(r).set(s, a)), a.add(o); } return { async next() { return i ? i.length === 0 ? t ? (i = void 0, this.next()) : (await new Promise((s) => { n = s; }), this.next()) : { done: !1, value: await i.shift() } : { done: !0 }; }, async return(s) { i = void 0; for (const a of e) { const c = tt(r, a); c && (c.delete(o), c.size === 0 && X.get(r).delete(a)); } return n(), arguments.length > 0 ? { done: !0, value: await s } : { done: !0 }; }, [Symbol.asyncIterator]() { return this; } }; } function Kn(r) { if (r === void 0) return Jn; if (!Array.isArray(r)) throw new TypeError("`methodNames` must be an array of strings"); for (const e of r) if (!Jn.includes(e)) throw typeof e != "string" ? new TypeError("`methodNames` element must be a string") : new Error(`${e} is not Emittery method`); return r; } const Ne = (r) => r === Gt || r === jt; function _t(r, e, t) { if (Ne(e)) try { Vt = !0, r.emit(e, t); } finally { Vt = !1; } } let yr = class Wr { static mixin(e, t) { return t = Kn(t), (n) => { if (typeof n != "function") throw new TypeError("`target` must be function"); for (const s of t) if (n.prototype[s] !== void 0) throw new Error(`The property \`${s}\` already exists on \`target\``); function i() { return Object.defineProperty(this, e, { enumerable: !1, value: new Wr() }), this[e]; } Object.defineProperty(n.prototype, e, { enumerable: !1, get: i }); const o = (s) => function(...a) { return this[e][s](...a); }; for (const s of t) Object.defineProperty(n.prototype, s, { enumerable: !1, value: o(s) }); return n; }; } static get isDebugEnabled() { var e, t; if (typeof ((e = globalThis.process) == null ? void 0 : e.env) != "object") return Mr; const { env: n } = (t = globalThis.process) != null ? t : { env: {} }; return n.DEBUG === "emittery" || n.DEBUG === "*" || Mr; } static set isDebugEnabled(e) { Mr = e; } constructor(e = {}) { var t; te.set(this, /* @__PURE__ */ new Set()), ge.set(this, /* @__PURE__ */ new Map()), X.set(this, /* @__PURE__ */ new Map()), X.get(this).set(Wt, /* @__PURE__ */ new Set()), this.debug = (t = e.debug) != null ? t : {}, this.debug.enabled === void 0 && (this.debug.enabled = !1), this.debug.logger || (this.debug.logger = (n, i, o, s) => { try { s = JSON.stringify(s); } catch { s = `Object with the following keys failed to stringify: ${Object.keys(s).join(",")}`; } (typeof o == "symbol" || typeof o == "number") && (o = o.toString()); const a = /* @__PURE__ */ new Date(), c = `${a.getHours()}:${a.getMinutes()}:${a.getSeconds()}.${a.getMilliseconds()}`; console.log(`[${c}][emittery:${n}][${i}] Event Name: ${o} data: ${s}`); }); } logIfDebugEnabled(e, t, n) { (Wr.isDebugEnabled || this.debug.enabled) && this.debug.logger(e, this.debug.name, t, n); } on(e, t) { Et(t), e = Array.isArray(e) ? e : [e]; for (const n of e) { ke(n); let i = Re(this, n); i || (i = /* @__PURE__ */ new Set(), ge.get(this).set(n, i)), i.add(t), this.logIfDebugEnabled("subscribe", n, void 0), Ne(n) || _t(this, Gt, { eventName: n, listener: t }); } return this.off.bind(this, e, t); } off(e, t) { Et(t), e = Array.isArray(e) ? e : [e]; for (const n of e) { ke(n); const i = Re(this, n); i && (i.delete(t), i.size === 0 && ge.get(this).delete(n)), this.logIfDebugEnabled("unsubscribe", n, void 0), Ne(n) || _t(this, jt, { eventName: n, listener: t }); } } once(e) { let t; const n = new Promise((i) => { t = this.on(e, (o) => { t(), i(o); }); }); return n.off = t, n; } events(e) { e = Array.isArray(e) ? e : [e]; for (const t of e) ke(t); return Xn(this, e); } async emit(e, t) { var n; if (ke(e), Ne(e) && !Vt) throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`"); this.logIfDebugEnabled("emit", e, t), Ns(this, e, t); const i = (n = Re(this, e)) != null ? n : /* @__PURE__ */ new Set(), o = te.get(this), s = [...i], a = Ne(e) ? [] : [...o]; await Qn, await Promise.all([ ...s.map(async (c) => { if (i.has(c)) return c(t); }), ...a.map(async (c) => { if (o.has(c)) return c(e, t); }) ]); } async emitSerial(e, t) { var n; if (ke(e), Ne(e) && !Vt) throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`"); this.logIfDebugEnabled("emitSerial", e, t); const i = (n = Re(this, e)) != null ? n : /* @__PURE__ */ new Set(), o = te.get(this), s = [...i], a = [...o]; await Qn; for (const c of s) i.has(c) && await c(t); for (const c of a) o.has(c) && await c(e, t); } onAny(e) { return Et(e), this.logIfDebugEnabled("subscribeAny", void 0, void 0), te.get(this).add(e), _t(this, Gt, { listener: e }), this.offAny.bind(this, e); } anyEvent() { return Xn(this); } offAny(e) { Et(e), this.logIfDebugEnabled("unsubscribeAny", void 0, void 0), _t(this, jt, { listener: e }), te.get(this).delete(e); } clearListeners(e) { e = Array.isArray(e) ? e : [e]; for (const t of e) if (this.logIfDebugEnabled("clear", t, void 0), typeof t == "string" || typeof t == "symbol" || typeof t == "number") { const n = Re(this, t); n && n.clear(); const i = tt(this, t); if (i) { for (const o of i) o.finish(); i.clear(); } } else { te.get(this).clear(); for (const [n, i] of ge.get(this).entries()) i.clear(), ge.get(this).delete(n); for (const [n, i] of X.get(this).entries()) { for (const o of i) o.finish(); i.clear(), X.get(this).delete(n); } } } listenerCount(e) { var t, n, i, o, s, a; e = Array.isArray(e) ? e : [e]; let c = 0; for (const u of e) { if (typeof u == "string") { c += te.get(this).size + ((n = (t = Re(this, u)) == null ? void 0 : t.size) != null ? n : 0) + ((o = (i = tt(this, u)) == null ? void 0 : i.size) != null ? o : 0) + ((a = (s = tt(this)) == null ? void 0 : s.size) != null ? a : 0); continue; } typeof u < "u" && ke(u), c += te.get(this).size; for (const f of ge.get(this).values()) c += f.size; for (const f of X.get(this).values()) c += f.size; } return c; } bindMethods(e, t) { if (typeof e != "object" || e === null) throw new TypeError("`target` must be an object"); t = Kn(t); for (const n of t) { if (e[n] !== void 0) throw new Error(`The property \`${n}\` already exists on \`target\``); Object.defineProperty(e, n, { enumerable: !1, value: this[n].bind(this) }); } } }; const Jn = Object.getOwnPropertyNames(yr.prototype).filter((r) => r !== "constructor"); Object.defineProperty(yr, "listenerAdded", { value: Gt, writable: !1, enumerable: !0, configurable: !1 }); Object.defineProperty(yr, "listenerRemoved", { value: jt, writable: !1, enumerable: !0, configurable: !1 }); function $s(r) { return r.onAny && r.emit; } function Ws(r) { return r.prototype.onAny && r.prototype.emit; } let Gs = 0; async function js(r, e, t) { const n = Ws(r) ? new yr() : {}, i = Gs++; return Object.getOwnPropertyNames(r.prototype).forEach( (o) => { n[o] = (...s) => Nt(e, U.FORWARD, o, s, t); } ), n.terminate = async (...o) => { const s = await Nt( e, U.TERMINATE, "", o, t ); return delete $t[i], e.terminate(), n.workerContext.worker = void 0, s; }, n.workerContext = { id: i, worker: e, resolvers: t }, $t[i] = n, n; } async function Vs(r, e) { const t = /* @__PURE__ */ new Map(); let n; const i = await Us( r, e, t, (o, s) => { n?.emit && n?.emit(o, s); } ); return n = await js( r, i, t ), n; } async function Hs(r, e) { const { functionName: t, args: n } = r; if (!e.instance) throw "instance not initialized"; if (!t) throw "missing function name to call"; if (!e.instance[t]) throw `undefined function [${t}] in class ${e.instance.constructor.workerId}`; Ve(r, await e.instance[t](...n ?? [])); } const Di = sn("registeredWorkers", {}); function Ys(r, e) { e.workerId = r, an() && (Di[e.workerId] = e); } function qs(r, e) { if (!r.args) throw "Missing className while initializing worker"; const [t, n] = r.args, i = Di[t]; if (i) e.instance = new i(r.args.slice(1)); else throw `unknown worker class ${t}`; ot(n, je), $s(e.instance) && e.instance.onAny((o, s) => { Ve( { type: U.EVENT }, { name: o, data: s } ); }), Ve(r, typeof e.instance !== void 0); } async function Qs(r, e) { const { args: t } = r; if (!e.instance) throw "instance not initialized"; let n; e.instance.terminate && (n = await e.instance.terminate(...t ?? [])), Ve(r, n); } function Xs(r) { if (!r.args) throw "Missing globals while syncing"; ot(r.args[0], je), Ve(r, {}); } function Ks() { const r = {}; onmessage = async (e) => { const t = e.data; switch (t.type) { case U.INIT: qs(t, r); break; case U.FORWARD: Hs(t, r); break; case U.TERMINATE: Qs(t, r); break; case U.GLOBALS_SYNC: Xs(t); break; } }; } an() && Ks(); const Bi = '(function(){"use strict";function z(r,e){globalThis.vonage||(globalThis.vonage={}),globalThis.vonage.workerizer||(globalThis.vonage.workerizer={});let t=globalThis.vonage.workerizer;return t[r]||(t[r]=e),t[r]}const P=z("globals",{});var d=(r=>(r.INIT="INIT",r.FORWARD="FORWARD",r.TERMINATE="TERMINATE",r.GLOBALS_SYNC="GLOBALS_SYNC",r.EVENT="EVENT",r))(d||{});function D(r){return[ImageBitmap,ReadableStream,WritableStream].some(t=>r instanceof t)}function w(r,e){const{id:t,type:s}=r,i=Array.isArray(e)?e:[e];postMessage({id:t,type:s,result:e},i.filter(n=>D(n)))}z("workerized",{});function W(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}function A(r,e){if(Array.isArray(e))e.splice(0,e.length);else if(typeof e=="object")for(const t in e)delete e[t];for(const t in r)Array.isArray(r[t])?(e[t]=[],A(r[t],e[t])):typeof r[t]=="object"?(e[t]={},A(r[t],e[t])):e[t]=r[t]}const c=new WeakMap,u=new WeakMap,a=new WeakMap,T=Symbol("anyProducer"),$=Promise.resolve(),k=Symbol("listenerAdded"),S=Symbol("listenerRemoved");let I=!1,m=!1;function h(r){if(typeof r!="string"&&typeof r!="symbol"&&typeof r!="number")throw new TypeError("`eventName` must be a string, symbol, or number")}function M(r){if(typeof r!="function")throw new TypeError("listener must be a function")}function b(r,e){const t=u.get(r);if(t.has(e))return t.get(e)}function E(r,e){const t=typeof e=="string"||typeof e=="symbol"||typeof e=="number"?e:T,s=a.get(r);if(s.has(t))return s.get(t)}function B(r,e,t){const s=a.get(r);if(s.has(e))for(const i of s.get(e))i.enqueue(t);if(s.has(T)){const i=Promise.all([e,t]);for(const n of s.get(T))n.enqueue(i)}}function j(r,e){e=Array.isArray(e)?e:[e];let t=!1,s=()=>{},i=[];const n={enqueue(o){i.push(o),s()},finish(){t=!0,s()}};for(const o of e){let f=E(r,o);f||(f=new Set,a.get(r).set(o,f)),f.add(n)}return{async next(){return i?i.length===0?t?(i=void 0,this.next()):(await new Promise(o=>{s=o}),this.next()):{done:!1,value:await i.shift()}:{done:!0}},async return(o){i=void 0;for(const f of e){const l=E(r,f);l&&(l.delete(n),l.size===0&&a.get(r).delete(f))}return s(),arguments.length>0?{done:!0,value:await o}:{done:!0}},[Symbol.asyncIterator](){return this}}}function L(r){if(r===void 0)return R;if(!Array.isArray(r))throw new TypeError("`methodNames` must be an array of strings");for(const e of r)if(!R.includes(e))throw typeof e!="string"?new TypeError("`methodNames` element must be a string"):new Error(`${e} is not Emittery method`);return r}const g=r=>r===k||r===S;function O(r,e,t){if(g(e))try{I=!0,r.emit(e,t)}finally{I=!1}}class y{static mixin(e,t){return t=L(t),s=>{if(typeof s!="function")throw new TypeError("`target` must be function");for(const o of t)if(s.prototype[o]!==void 0)throw new Error(`The property \\`${o}\\` already exists on \\`target\\``);function i(){return Object.defineProperty(this,e,{enumerable:!1,value:new y}),this[e]}Object.defineProperty(s.prototype,e,{enumerable:!1,get:i});const n=o=>function(...f){return this[e][o](...f)};for(const o of t)Object.defineProperty(s.prototype,o,{enumerable:!1,value:n(o)});return s}}static get isDebugEnabled(){var e,t;if(typeof((e=globalThis.process)==null?void 0:e.env)!="object")return m;const{env:s}=(t=globalThis.process)!=null?t:{env:{}};return s.DEBUG==="emittery"||s.DEBUG==="*"||m}static set isDebugEnabled(e){m=e}constructor(e={}){var t;c.set(this,new Set),u.set(this,new Map),a.set(this,new Map),a.get(this).set(T,new Set),this.debug=(t=e.debug)!=null?t:{},this.debug.enabled===void 0&&(this.debug.enabled=!1),this.debug.logger||(this.debug.logger=(s,i,n,o)=>{try{o=JSON.stringify(o)}catch{o=`Object with the following keys failed to stringify: ${Object.keys(o).join(",")}`}(typeof n=="symbol"||typeof n=="number")&&(n=n.toString());const f=new Date,l=`${f.getHours()}:${f.getMinutes()}:${f.getSeconds()}.${f.getMilliseconds()}`;console.log(`[${l}][emittery:${s}][${i}] Event Name: ${n}\n data: ${o}`)})}logIfDebugEnabled(e,t,s){(y.isDebugEnabled||this.debug.enabled)&&this.debug.logger(e,this.debug.name,t,s)}on(e,t){M(t),e=Array.isArray(e)?e:[e];for(const s of e){h(s);let i=b(this,s);i||(i=new Set,u.get(this).set(s,i)),i.add(t),this.logIfDebugEnabled("subscribe",s,void 0),g(s)||O(this,k,{eventName:s,listener:t})}return this.off.bind(this,e,t)}off(e,t){M(t),e=Array.isArray(e)?e:[e];for(const s of e){h(s);const i=b(this,s);i&&(i.delete(t),i.size===0&&u.get(this).delete(s)),this.logIfDebugEnabled("unsubscribe",s,void 0),g(s)||O(this,S,{eventName:s,listener:t})}}once(e){let t;const s=new Promise(i=>{t=this.on(e,n=>{t(),i(n)})});return s.off=t,s}events(e){e=Array.isArray(e)?e:[e];for(const t of e)h(t);return j(this,e)}async emit(e,t){var s;if(h(e),g(e)&&!I)throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`");this.logIfDebugEnabled("emit",e,t),B(this,e,t);const i=(s=b(this,e))!=null?s:new Set,n=c.get(this),o=[...i],f=g(e)?[]:[...n];await $,await Promise.all([...o.map(async l=>{if(i.has(l))return l(t)}),...f.map(async l=>{if(n.has(l))return l(e,t)})])}async emitSerial(e,t){var s;if(h(e),g(e)&&!I)throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`");this.logIfDebugEnabled("emitSerial",e,t);const i=(s=b(this,e))!=null?s:new Set,n=c.get(this),o=[...i],f=[...n];await $;for(const l of o)i.has(l)&&await l(t);for(const l of f)n.has(l)&&await l(e,t)}onAny(e){return M(e),this.logIfDebugEnabled("subscribeAny",void 0,void 0),c.get(this).add(e),O(this,k,{listener:e}),this.offAny.bind(this,e)}anyEvent(){return j(this)}offAny(e){M(e),this.logIfDebugEnabled("unsubscribeAny",void 0,void 0),O(this,S,{listener:e}),c.get(this).delete(e)}clearListeners(e){e=Array.isArray(e)?e:[e];for(const t of e)if(this.logIfDebugEnabled("clear",t,void 0),typeof t=="string"||typeof t=="symbol"||typeof t=="number"){const s=b(this,t);s&&s.clear();const i=E(this,t);if(i){for(const n of i)n.finish();i.clear()}}else{c.get(this).clear();for(const[s,i]of u.get(this).entries())i.clear(),u.get(this).delete(s);for(const[s,i]of a.get(this).entries()){for(const n of i)n.finish();i.clear(),a.get(this).delete(s)}}}listenerCount(e){var t,s,i,n,o,f;e=Array.isArray(e)?e:[e];let l=0;for(const p of e){if(typeof p=="string"){l+=c.get(this).size+((s=(t=b(this,p))==null?void 0:t.size)!=null?s:0)+((n=(i=E(this,p))==null?void 0:i.size)!=null?n:0)+((f=(o=E(this))==null?void 0:o.size)!=null?f:0);continue}typeof p<"u"&&h(p),l+=c.get(this).size;for(const v of u.get(this).values())l+=v.size;for(const v of a.get(this).values())l+=v.size}return l}bindMethods(e,t){if(typeof e!="object"||e===null)throw new TypeError("`target` must be an object");t=L(t);for(const s of t){if(e[s]!==void 0)throw new Error(`The property \\`${s}\\` already exists on \\`target\\``);Object.defineProperty(e,s,{enumerable:!1,value:this[s].bind(this)})}}}const R=Object.getOwnPropertyNames(y.prototype).filter(r=>r!=="constructor");Object.defineProperty(y,"listenerAdded",{value:k,writable:!1,enumerable:!0,configurable:!1}),Object.defineProperty(y,"listenerRemoved",{value:S,writable:!1,enumerable:!0,configurable:!1});function C(r){return r.onAny&&r.emit}async function V(r,e){const{functionName:t,args:s}=r;if(!e.instance)throw"instance not initialized";if(!t)throw"missing function name to call";if(!e.instance[t])throw`undefined function [${t}] in class ${e.instance.constructor.workerId}`;w(r,await e.instance[t](...s??[]))}const _=z("registeredWorkers",{});function q(r,e){e.workerId=r,W()&&(_[e.workerId]=e)}function F(r,e){if(!r.args)throw"Missing className while initializing worker";const[t,s]=r.args,i=_[t];if(i)e.instance=new i(r.args.slice(1));else throw`unknown worker class ${t}`;A(s,P),C(e.instance)&&e.instance.onAny((n,o)=>{w({type:d.EVENT},{name:n,data:o})}),w(r,typeof e.instance!==void 0)}async function Y(r,e){const{args:t}=r;if(!e.instance)throw"instance not initialized";let s;e.instance.terminate&&(s=await e.instance.terminate(...t??[])),w(r,s)}function U(r){if(!r.args)throw"Missing globals while syncing";A(r.args[0],P),w(r,{})}function G(){const r={};onmessage=async e=>{const t=e.data;switch(t.type){case d.INIT:F(t,r);break;case d.FORWARD:V(t,r);break;case d.TERMINATE:Y(t,r);break;case d.GLOBALS_SYNC:U(t);break}}}W()&&G();class H{check(){return typeof globalThis.MediaStreamTrackProcessor<"u"&&typeof globalThis.VideoTrackGenerator<"u"}}q("IsSupportedWorkerized",H),G()})();\n', Zn = typeof self < "u" && self.Blob && new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);", Bi], { type: "text/javascript;charset=utf-8" }); function Js(r) { let e; try { if (e = Zn && (self.URL || self.webkitURL).createObjectURL(Zn), !e) throw ""; const t = new Worker(e, { name: r?.name }); return t.addEventListener("error", () => { (self.URL || self.webkitURL).revokeObjectURL(e); }), t; } catch { return new Worker( "data:text/javascript;charset=utf-8," + encodeURIComponent(Bi), { name: r?.name } ); } } class Li { check() { return typeof globalThis.MediaStreamTrackProcessor < "u" && typeof globalThis.VideoTrackGenerator < "u"; } } Ys("IsSupportedWorkerized", Li); async function Zs() { return new Promise(async (r, e) => { !ta() && (await Ui() || zi()) ? r() : e( "Your browser does not support the MediaStreamTrack API for Insertable Streams of Media." ); }); } function zi() { return self.MediaStreamTrackProcessor !== void 0 && self.MediaStreamTrackGenerator !== void 0 || ea(); } function ea() { return [ self.ReadableStream, self.WritableStream, self.MediaStream, self.OffscreenCanvas, self.VideoFrame, self.AudioContext, self.AudioWorkletNode ].filter((r) => r === void 0).length === 0; } function ta() { const r = navigator.userAgent.toLowerCase(); return navigator.vendor && navigator.vendor.toLowerCase().indexOf("apple") > -1 && !(r.indexOf("applewebkit") > -1 && r.indexOf("version") === -1) ? parseInt((r.split(" ").find((e) => e.includes("version/")) ?? "/0").split("/")[1]) < 26 : !1; } function Ui() { return Vs(Li, Js).then(async (r) => { const e = await r.check(); return await r.terminate(), e; }).catch(() => !1); } const re = /* @__PURE__ */ new WeakMap(), ye = /* @__PURE__ */ new WeakMap(), K = /* @__PURE__ */ new WeakMap(), Ht = /* @__PURE__ */ Symbol("anyProducer"), ei = Promise.resolve(), Yt = /* @__PURE__ */ Symbol("listenerAdded"), qt = /* @__PURE__ */ Symbol("listenerRemoved"); let Qt = !1, Cr = !1; const Xt = (r) => typeof r == "string" || typeof r == "symbol" || typeof r == "number"; function Pe(r) { if (!Xt(r)) throw new TypeError("`eventName` must be a string, symbol, or number"); } function At(r) { if (typeof r != "function") throw new TypeError("listener must be a function"); } function Fe(r, e) { const t = ye.get(r); if (t.has(e)) return t.get(e); } function rt(r, e) { const t = Xt(e) ? e : Ht, n = K.get(r); if (n.has(t)) return n.get(t); } function ra(r, e, t) { const n = K.get(r); if (n.has(e)) for (const i of n.get(e)) i.enqueue(t); if (n.has(Ht)) { const i = Promise.all([e, t]); for (const o of n.get(Ht)) o.enqueue(i); } } function ti(r, e) { e = Array.isArray(e) ? e : [e]; let t = !1, n = () => { }, i = []; const o = { enqueue(s) { i.push(s), n(); }, finish() { t = !0, n(); } }; for (const s of e) { let a = rt(r, s); a || (a = /* @__PURE__ */ new Set(), K.get(r).set(s, a)), a.add(o); } return { async next() { return i ? i.length === 0 ? t ? (i = void 0, this.next()) : (await new Promise((s) => { n = s; }), this.next()) : { done: !1, value: await i.shift() } : { done: !0 }; }, async return(s) { i = void 0; for (const a of e) { const c = rt(r, a); c && (c.delete(o), c.size === 0 && K.get(r).delete(a)); } return n(), arguments.length > 0 ? { done: !0, value: await s } : { done: !0 }; }, [Symbol.asyncIterator]() { return this; } }; } function ri(r) { if (r === void 0) return ni; if (!Array.isArray(r)) throw new TypeError("`methodNames` must be an array of strings"); for (const e of r) if (!ni.includes(e)) throw typeof e != "string" ? new TypeError("`methodNames` element must be a string") : new Error(`${e} is not Emittery method`); return r; } const $e = (r) => r === Yt || r === qt; function Tt(r, e, t) { if ($e(e)) try { Qt = !0, r.emit(e, t); } finally { Qt = !1; } } let Qe = class Gr { static mixin(e, t) { return t = ri(t), (n) => { if (typeof n != "function") throw new TypeError("`target` must be function"); for (const s of t) if (n.prototype[s] !== void 0) throw new Error(`The property \`${s}\` already exists on \`target\``); function i() { return Object.defineProperty(this, e, { enumerable: !1, value: new Gr() }), this[e]; } Object.defineProperty(n.prototype, e, { enumerable: !1, get: i }); const o = (s) => function(...a) { return this[e][s](...a); }; for (const s of t) Object.defineProperty(n.prototype, s, { enumerable: !1, value: o(s) }); return n; }; } static get isDebugEnabled() { if (typeof globalThis.process?.env != "object") return Cr; const { env: e } = globalThis.process ?? { env: {} }; return e.DEBUG === "emittery" || e.DEBUG === "*" || Cr; } static set isDebugEnabled(e) { Cr = e; } constructor(e = {}) { re.set(this, /* @__PURE__ */ new Set()), ye.set(this, /* @__PURE__ */ new Map()), K.set(this, /* @__PURE__ */ new Map()), K.get(this).set(Ht, /* @__PURE__ */ new Set()), this.debug = e.debug ?? {}, this.debug.enabled === void 0 && (this.debug.enabled = !1), this.debug.logger || (this.debug.logger = (t, n, i, o) => { try { o = JSON.stringify(o); } catch { o = `Object with the following keys failed to stringify: ${Object.keys(o).join(",")}`; } (typeof i == "symbol" || typeof i == "number") && (i = i.toString()); const s = /* @__PURE__ */ new Date(), a = `${s.getHours()}:${s.getMinutes()}:${s.getSeconds()}.${s.getMilliseconds()}`; console.log(`[${a}][emittery:${t}][${n}] Event Name: ${i} data: ${o}`); }); } logIfDebugEnabled(e, t, n) { (Gr.isDebugEnabled || this.debug.enabled) && this.debug.logger(e, this.debug.name, t, n); } on(e, t, { signal: n } = {}) { At(t), e = Array.isArray(e) ? e : [e]; for (const o of e) { Pe(o); let s = Fe(this, o); s || (s = /* @__PURE__ */ new Set(), ye.get(this).set(o, s)), s.add(t), this.logIfDebugEnabled("subscribe", o, void 0), $e(o) || Tt(this, Yt, { eventName: o, listener: t }); } const i = () => { this.off(e, t), n?.removeEventListener("abort", i); }; return n?.addEventListener("abort", i, { once: !0 }), n?.aborted && i(), i; } off(e, t) { At(t), e = Array.isArray(e) ? e : [e]; for (const n of e) { Pe(n); const i = Fe(this, n); i && (i.delete(t), i.size === 0 && ye.get(this).delete(n)), this.logIfDebugEnabled("unsubscribe", n, void 0), $e(n) || Tt(this, qt, { eventName: n, listener: t }); } } once(e, t) { if (t !== void 0 && typeof t != "function") throw new TypeError("predicate must be a function"); let n; const i = new Promise((o) => { n = this.on(e, (s) => { t && !t(s) || (n(), o(s)); }); }); return i.off = n, i; } events(e) { e = Array.isArray(e) ? e : [e]; for (const t of e) Pe(t); return ti(this, e); } async emit(e, t) { if (Pe(e), $e(e) && !Qt) throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`"); this.logIfDebugEnabled("emit", e, t), ra(this, e, t); const n = Fe(this, e) ?? /* @__PURE__ */ new Set(), i = re.get(this), o = [...n], s = $e(e) ? [] : [...i]; await ei, await Promise.all([ ...o.map(async (a) => { if (n.has(a)) return a(t); }), ...s.map(async (a) => { if (i.has(a)) return a(e, t); }) ]); } async emitSerial(e, t) { if (Pe(e), $e(e) && !Qt) throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`"); this.logIfDebugEnabled("emitSerial", e, t); const n = Fe(this, e) ?? /* @__PURE__ */ new Set(), i = re.get(this), o = [...n], s = [...i]; await ei; for (const a of o) n.has(a) && await a(t); for (const a of s) i.has(a) && await a(e, t); } onAny(e, { signal: t } = {}) { At(e), this.logIfDebugEnabled("subscribeAny", void 0, void 0), re.get(this).add(e), Tt(this, Yt, { listener: e }); const n = () => { this.offAny(e), t?.removeEventListener("abort", n); }; return t?.addEventListener("abort", n, { once: !0 }), t?.aborted && n(), n; } anyEvent() { return ti(this); } offAny(e) { At(e), this.logIfDebugEnabled("unsubscribeAny", void 0, void 0), Tt(this, qt, { listener: e }), re.get(this).delete(e); } clearListeners(e) { e = Array.isArray(e) ? e : [e]; for (const t of e) if (this.logIfDebugEnabled("clear", t, void 0), Xt(t)) { const n = Fe(this, t); n && n.clear(); const i = rt(this, t); if (i) { for (const o of i) o.finish(); i.clear(); } } else { re.get(this).clear(); for (const [n, i] of ye.get(this).entries()) i.clear(), ye.get(this).delete(n); for (const [n, i] of K.get(this).entries()) { for (const o of i) o.finish(); i.clear(), K.get(this).delete(n); } } } listenerCount(e) { e = Array.isArray(e) ? e : [e]; let t = 0; for (const n of e) { if (Xt(n)) { t += re.get(this).size + (Fe(this, n)?.size ?? 0) + (rt(this, n)?.size ?? 0) + (rt(this)?.size ?? 0); continue; } n !== void 0 && Pe(n), t += re.get(this).size; for (const i of ye.get(this).values()) t += i.size; for (const i of K.get(this).values()) t += i.size; } return t; } bindMethods(e, t) { if (typeof e != "object" || e === null) throw new TypeError("`target` must be an object"); t = ri(t); for (const n of t) { if (e[n] !== void 0) throw new Error(`The property \`${n}\` already exists on \`target\``); Object.defineProperty(e, n, { enumerable: !1, value: this[n].bind(this) }); } } }; const ni = Object.getOwnPropertyNames(Qe.prototype).filter((r) => r !== "constructor"); Object.defineProperty(Qe, "listenerAdded", { value: Yt, writable: !1, enumerable: !0, configurable: !1 }); Object.defineProperty(Qe, "listenerRemoved", { value: qt, writable: !1, enumerable: !0, configurable: !1 }); var na = Object.defineProperty, ia = (r, e, t) => e in r ? na(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, oa = (r, e, t) => (ia(r, e + "", t), t); const sa = "hlg.tokbox.com/prod/logging/vcp_webrtc", aa = "https://", ca = 1e4, F = []; for (let r = 0; r < 256; ++r) F.push((r + 256).toString(16).slice(1)); function ua(r, e = 0) { return (F[r[e + 0]] + F[r[e + 1]] + F[r[e + 2]] + F[r[e + 3]] + "-" + F[r[e + 4]] + F[r[e + 5]] + "-" + F[r[e + 6]] + F[r[e + 7]] + "-" + F[r[e + 8]] + F[r[e + 9]] + "-" + F[r[e + 10]] + F[r[e + 11]] + F[r[e + 12]] + F[r[e + 13]] + F[r[e + 14]] + F[r[e + 15]]).toLowerCase(); } const la = new Uint8Array(16); function fa() { return crypto.getRandomValues(la); } function da(r, e, t) { return crypto.randomUUID ? crypto.randomUUID() : ha(r); } function ha(r, e, t) { var n, i, o; r = r || {}; const s = (o = (i = r.random) != null ? i : (n = r.rng) == null ? void 0 : n.call(r)) != null ? o : fa(); if (s.length < 16) throw new Error("Random bytes length must be >= 16"); return s[6] = s[6] & 15 | 64, s[8] = s[8] & 63 | 128, ua(s); } function cn(r, e) { globalThis.vonage || (globalThis.vonage = {}), globalThis.vonage.workerizer || (globalThis.vonage.workerizer = {}); let t = globalThis.vonage.workerizer; return t[r] || (t[r] = e), t[r]; } const se = cn( "globals", {} ); var xe = /* @__PURE__ */ ((r) => (r.INIT = "INIT", r.FORWARD = "FORWARD", r.TERMINATE = "TERMINATE", r.GLOBALS_SYNC = "GLOBALS_SYNC", r))(xe || {}); function Ni(r) { return [ImageBitmap, ReadableStream, WritableStream].some((e) => r instanceof e); } let ma = 0; function pa(r, e, t, n, i) { const o = ma++; return r.postMessage( { id: o, type: e, functionName: t, args: n }, n.filter((s) => Ni(s)) ), new Promise((s) => { i?.set(o, s); }); } function lt(r, e) { const { id: t, type: n } = r, i = Array.isArray(e) ? e : [e]; postMessage( { id: t, type: n, result: e }, i.filter((o) => Ni(o)) ); } const ii = cn("workerized", {}); function $i() { return typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope; } async function ga() { if ($i()) lt({ type: xe.GLOBALS_SYNC }, se); else { const r = []; for (const e in ii) { const { worker: t, resolvers: n } = ii[e].workerContext; t && r.push( pa( t, xe.GLOBALS_SYNC, "", [se], n ) ); } await Promise.all(r); } } function Kt(r, e) { if (Array.isArray(e)) e.splice(0, e.length); else if (typeof e == "object") for (const t in e) delete e[t]; for (const t in r) Array.isArray(r[t]) ? (e[t] = [], Kt(r[t], e[t])) : typeof r[t] == "object" ? (e[t] = {}, Kt(r[t], e[t])) : e[t] = r[t]; } async function ya(r, e) { const { functionName: t, args: n } = r; if (!e.instance) throw "instance not initialized"; if (!t) throw "missing function name to call"; if (!e.instance[t]) throw `undefined function [${t}] in class ${e.instance.constructor.workerId}`; lt(r, await e.instance[t](...n ?? [])); } const ba = cn("registeredWorkers", {}); function wa(r, e) { if (!r.args) throw "Missing className while initializing worker"; const [t, n] = r.args, i = ba[t]; if (i) e.instance = new i(r.args.slice(1)); else throw `unknown worker class ${t}`; Kt(n, se), lt(r, typeof e.instance !== void 0); } async function va(r, e) { const { args: t } = r; if (!e.instance) throw "instance not initialized"; let n; e.instance.terminate && (n = await e.instance.terminate(...t ?? [])), lt(r, n); } function xa(r) { if (!r.args) throw "Missing globals while syncing"; Kt(r.args[0], se), lt(r, {}); } function Ea() { const r = {}; onmessage = async (e) => { const t = e.data; switch (t.type) { case xe.INIT: wa(t, r); break; case xe.FORWARD: ya(t, r); break; case xe.TERMINATE: va(t, r); break; case xe.GLOBALS_SYNC: xa(t); break; } }; } $i() && Ea(); function _a(r, e) { return se[r] || (se[r] = e), [ () => se[r], async (t) => { se[r] = t, await ga(); } ]; } function Aa(r, e) { return _a(r, e); } const [Ta, Sa] = Aa("metadata"); function Ia(r) { Sa(r); } function Lt() { return Ta(); } class un { constructor(e, t) { oa(this, "uuid"), this.config = e, this.uuid = t ?? da(); } async send(e) { var t, n, i; const { appId: o, sourceType: s } = (t = Lt()) != null ? t : {}; if (!o || !s) return "metadata missing"; const a = new AbortController(), c = setTimeout(() => a.abort(), ca); return await ((i = (n = this.config) == null ? void 0 : n.fetch) != null ? i : fetch)(this.getUrl(), { method: "POST", headers: this.getHeaders(), body: JSON.stringify(this.buildReport(e)), signal: a.signal }), clearTimeout(c), "success"; } getUrl() { var e; let t = (e = Lt().proxyUrl) != null ? e : aa; return t += (t.at(-1) === "/" ? "" : "/") + sa, t; } getHeaders() { return { "Content-Type": "application/json" }; } buildReport(e) { const t = Lt(); return { guid: this.uuid, ...e, applicationId: t.appId, timestamp: Date.now(), proxyUrl: t.proxyUrl, source: t.sourceType }; } } const zt = "3.0.4", jr = class { }; jr.updates = { transformer_new: "New transformer", transformer_null: "Null transformer" }, jr.errors = { transformer_none: "No transformers provided", transformer_start: "Cannot start transformer", transformer_transform: "Cannot transform frame", transformer_flush: "Cannot flush transformer", readable_null: "Readable is null", writable_null: "Writable is null" }; let Ee = jr; function ka(r) { return typeof r == "object" && r !== null && "message" in r && typeof r.message == "string"; } function Ra(r) { if (ka(r)) return r; try { return new Error(JSON.stringify(r)); } catch { return new Error(String(r)); } } function Dr(r) { return Ra(r).message; } class Pa { constructor(e, t) { this.config = e, this.frameTransformedCount = 0, this.frameFromSourceCount = 0, this.startAt = 0, this.reporter = new un(e, t); } async onFrameFromSource() { this.frameFromSourceCount++; } get fps() { const { startAt: e, frameFromSourceCount: t } = this, n = (Date.now() - e) / 1e3; return t / n; } async onFrameTransformed(e = {}, t = !1) { this.startAt === 0 && (this.startAt = Date.now()), this.frameTransformedCount++; const { startAt: n, frameTransformedCount: i, frameFromSourceCount: o } = this, s = Date.now(), a = (s - n) / 1e3, c = i / a, u = o / a; return t || this.frameTransformedCount >= this.config.loggingIntervalFrameCount ? (this.frameFromSourceCount = 0, this.frameTransformedCount = 0, this.startAt = s, this.reporter.config = this.config, this.reporter.send({ ...this.config.report, variation: "QoS", fps: u, transformedFps: c, framesTransformed: i, ...e })) : "success"; } } var Fa = /* @__PURE__ */ ((r) => (r.FPS_DROP = "fps_drop", r))(Fa || {}), Oa = /* @__PURE__ */ ((r) => (r.start = "start", r.transform = "transform", r.flush = "flush", r))(Oa || {}), Vr = /* @__PURE__ */ ((r) => (r.pipeline_ended = "pipeline_ended", r.pipeline_ended_with_error = "pipeline_ended_with_error", r.pipeline_started = "pipeline_started", r.pipeline_started_with_error = "pipeline_started_with_error", r.pipeline_restarted = "pipeline_restarted", r.pipeline_restarted_with_error = "pipeline_restarted_with_error", r))(Vr || {}); const Ma = 500, Ca = 0.8; class Da extends Qe { constructor(e, t) { super(), this.reporter_ = new un(), this.reporterQos_ = new Pa({ loggingIntervalFrameCount: Ma, report: { version: zt } }), this.index_ = t, this.transformer_ = e, this.shouldStop_ = !1, this.isFlashed_ = !1, this.mediaTransformerQosReportStartTimestamp_ = 0, this.videoHeight_ = 0, this.videoWidth_ = 0, this.trackExpectedRate_ = -1, this.transformerType_ = "Custom", "getTransformerType" in e && (this.transformerType_ = e.getTransformerType()), this.report({ variation: "Create" }); } setTrackExpectedRate(e) { this.trackExpectedRate_ = e; } async start(e) { if (this.controller_ = e, this.transformer_ && typeof this.transformer_.start == "function") try { await this.transformer_.start(e); } catch (t) { this.report({ message: Ee.errors.transformer_start, variation: "Error", error: Dr(t) }); const n = { eventMetaData: { transformerIndex: this.index_ }, error: t, function: "start" /* start */ }; this.emit("error", n); } } async transform(e, t) { if (this.mediaTransformerQosReportStartTimestamp_ === 0 && (this.mediaTransformerQosReportStartTimestamp_ = Date.now()), e instanceof VideoFrame && (this.videoHeight_ = e?.displayHeight ?? 0, this.videoWidth_ = e?.displayWidth ?? 0), this.reporterQos_.onFrameFromSource(), this.transformer_) if (this.shouldStop_) console.warn("[Pipeline] flush from transform"), e.close(), this.flush(t), t.terminate(); else { try { await this.transformer_.transform?.(e, t), this.reportQos(); } catch (n) { this.report({ message: Ee.errors.transformer_transform, variation: "Error", error: Dr(n) }); const i = { eventMetaData: { transformerIndex: this.index_ }, error: n, function: "transform" /* transform */ }; this.emit("error", i); } if (this.trackExpectedRate_ != -1 && this.trackExpectedRate_ * Ca > this.reporterQos_.fps) { const n = { eventMetaData: { transformerIndex: this.index_ }, warningType: "fps_drop", dropInfo: { requested: this.trackExpectedRate_, current: this.reporterQos_.fps } }; this.emit("warn", n); } } } async flush(e) { if (this.transformer_ && typeof this.transformer_.flush == "function" && !this.isFlashed_) { this.isFlashed_ = !0; try { await this.transformer_.flush(e); } catch (t) { this.report({ message: Ee.errors.transformer_flush, variation: "Error", error: Dr(t) }); const n = { eventMetaData: { transformerIndex: this.index_ }, error: t, function: "flush" /* flush */ }; this.emit("error", n); } } this.reportQos(!0), this.report({ variation: "Delete" }); } stop() { console.log("[Pipeline] Stop stream."), this.controller_ && (this.flush(this.controller_), this.controller_.terminate()), this.shouldStop_ = !0; } report(e) { this.reporter_.send({ version: zt, action: "MediaTransformer", transformerType: this.transformerType_, ...e }); } reportQos(e = !1) { this.reporterQos_.config = { ...this.reporterQos_.config }, this.reporterQos_.onFrameTransformed( { version: zt, action: "MediaTransformer", transformerType: this.transformerType_, videoWidth: this.videoWidth_, videoHeight: this.videoHeight_ }, e ); } } class Ba extends Qe { constructor(e) { super(), this.transformers_ = [], this.trackExpectedRate_ = -1; for (let t = 0; t < e.length; t++) { let n = new Da(e[t], t); n.on("error", (i) => { this.emit("error", i); }), n.on("warn", (i) => { this.emit("warn", i); }), this.transformers_.push(n); } } setTrackExpectedRate(e) { this.trackExpectedRate_ = e; for (let t of this.transformers_) t.setTrackExpectedRate(this.trackExpectedRate_); } async start(e, t) { if (!this.transformers_ || this.transformers_.length === 0) { console.log("[Pipeline] No transformers."); return; } try { let n = e; for (let i of this.transformers_) e = e.pipeThrough( new TransformStream(i) ); e.pipeTo(t).then(async () => { console.log("[Pipeline] Setup."), await t.abort(), await n.cancel(), this.emit( "pipelineInfo", "pipeline_ended" /* pipeline_ended */ ); }).catch(async (i) => { e.cancel().then(() => { console.log( "[Pipeline] Shutting down streams after abort." ); }).catch((o) => { console.error( "[Pipeline] Error from stream transform:", o ); }), await t.abort(i), await n.cancel(i), this.emit( "pipelineInfo", "pipeline_ended_with_error" /* pipeline_ended_with_error */ ); }); } catch { this.emit( "pipelineInfo", "pipeline_started_with_error" /* pipeline_started_with_error */ ), this.destroy(); return; } this.emit( "pipelineInfo", "pipeline_started" /* pipeline_started */ ), console.log("[Pipeline] Pipeline started."); } async destroy() { console.log("[Pipeline] Destroying Pipeline."); for (let e of this.transformers_) e.stop(); } } class Wi extends Qe { constructor() { super(), this.reporter_ = new un(), this.trackExpectedRate_ = -1, this.report({ variation: "Create" }); } /** * Sets the expected rate of the track per second. * The media processor will use this number for calculating drops in the rate. * This could happen when the transformation will take more time than expected. * This will not cause an error, just warning to the client. * Mostly: * Video: 30 frames per second * Audio: 50 audio data per second for OPUS * In case of increased frame dropping rate a warning will be emitted according to info [here](/docs/intro#errors-and-warnings-listener). * ***This is an optional method.*** * @param trackExpectedRate - number holds the predicted track rate. */ setTrackExpectedRate(e) { this.trackExpectedRate_ = e, this.pipeline_ && this.pipeline_.setTrackExpectedRate(this.trackExpectedRate_); } async transform(e, t) { if (this.isTrack(e)) { if (e.kind === "video") { const n = new MediaStreamTrackProcessor({ track: e }), i = new VideoTrackGenerator(); return this.readable_ = n.readable, this.writable_ = i.writable, await this.transformInternal(), i.track; } throw Error("Cannot process audio tracks inside a web worker when passing a track to transform"); } else return this.readable_ = e, this.writable_ = t, this.transformInternal(); } /** * @private */ transformInternal() { return new Promise(async (e, t) => { if (!this.transformers_ || this.transformers_.length === 0) { this.report({ message: Ee.errors.transformer_none, variation: "Error" }), t("[MediaProcessor] Need to set transformers."); return; } if (!this.readable_) { this.report({ variation: "Error", message: Ee.errors.readable_null }), t("[MediaProcessor] Readable is null."); return; } if (!this.writable_) { this.report({ variation: "Error", message: Ee.errors.writable_null }), t("[MediaProcessor] Writable is null."); return; } let n = !1; this.pipeline_ && (n = !0, this.pipeline_.clearListeners(), this.pipeline_.destroy()), this.pipeline_ = new Ba(this.transformers_), this.pipeline_.on("warn", (i) => { this.emit("warn", i); }), this.pipeline_.on("error", (i) => { this.emit("error", i); }), this.pipeline_.on("pipelineInfo", (i) => { n && (i === "pipeline_started" ? i = Vr.pipeline_restarted : i === "pipeline_started_with_error" && (i = Vr.pipeline_restarted_with_error)), this.emit("pipelineInfo", i); }), this.trackExpectedRate_ != -1 && this.pipeline_.setTrackExpectedRate(this.trackExpectedRate_), this.pipeline_.start(this.readable_, this.writable_).then(() => { e(); }).catch((i) => { t(i); }); }); } /** * Sets an array of transfromer instances that will be hold and ran by the media processor instance. * See example [here](/docs/intro#main-code) * * @param transformers An array of transformer instances. * * @returns */ setTransformers(e) { return this.report({ variation: "Update", message: Ee.updates.transformer_new }), this.transformers_ = e, this.readable_ && this.writable_ ? this.transformInternal() : Promise.resolve(); } /** * Stops running the tranformation logic performed by the media processor instance. * @ret