@vonage/ml-transformers
Version:
<!-- README for NPM; the one for GitHub is in .github directory. -->
4 lines • 270 kB
JavaScript
(function(R,me){typeof exports=="object"&&typeof module<"u"?me(exports):typeof define=="function"&&define.amd?define(["exports"],me):(R=typeof globalThis<"u"?globalThis:R||self,me(R["ml-transformers"]={}))})(this,(function(R){"use strict";function me(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 Pe=me("globals",{});var U=(r=>(r.INIT="INIT",r.FORWARD="FORWARD",r.TERMINATE="TERMINATE",r.GLOBALS_SYNC="GLOBALS_SYNC",r.EVENT="EVENT",r))(U||{});function Wn(r){return[ImageBitmap,ReadableStream,WritableStream].some(e=>r instanceof e)}let cs=0;function xt(r,e,t,n,i){const o=cs++;return r.postMessage({id:o,type:e,functionName:t,args:n},n.filter(s=>Wn(s))),new Promise(s=>{i?.set(o,s)})}function Fe(r,e){const{id:t,type:n}=r,i=Array.isArray(e)?e:[e];postMessage({id:t,type:n,result:e},i.filter(o=>Wn(o)))}const Et=me("workerized",{});function Cr(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}async function us(){if(Cr())Fe({type:U.GLOBALS_SYNC},Pe);else{const r=[];for(const e in Et){const{worker:t,resolvers:n}=Et[e].workerContext;t&&r.push(xt(t,U.GLOBALS_SYNC,"",[Pe],n))}await Promise.all(r)}}function Je(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]=[],Je(r[t],e[t])):typeof r[t]=="object"?(e[t]={},Je(r[t],e[t])):e[t]=r[t]}async function ls(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)):(Je((u=o.result)!=null?u:{},Pe),await us());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 xt(i,U.INIT,"",[r.workerId,Pe],t))throw"Failed to instantiate workerized class";return i}const te=new WeakMap,pe=new WeakMap,Q=new WeakMap,_t=Symbol("anyProducer"),Gn=Promise.resolve(),At=Symbol("listenerAdded"),Tt=Symbol("listenerRemoved");let St=!1,Dr=!1;function Oe(r){if(typeof r!="string"&&typeof r!="symbol"&&typeof r!="number")throw new TypeError("`eventName` must be a string, symbol, or number")}function It(r){if(typeof r!="function")throw new TypeError("listener must be a function")}function Me(r,e){const t=pe.get(r);if(t.has(e))return t.get(e)}function Ze(r,e){const t=typeof e=="string"||typeof e=="symbol"||typeof e=="number"?e:_t,n=Q.get(r);if(n.has(t))return n.get(t)}function fs(r,e,t){const n=Q.get(r);if(n.has(e))for(const i of n.get(e))i.enqueue(t);if(n.has(_t)){const i=Promise.all([e,t]);for(const o of n.get(_t))o.enqueue(i)}}function jn(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=Ze(r,s);a||(a=new Set,Q.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=Ze(r,a);c&&(c.delete(o),c.size===0&&Q.get(r).delete(a))}return n(),arguments.length>0?{done:!0,value:await s}:{done:!0}},[Symbol.asyncIterator](){return this}}}function Vn(r){if(r===void 0)return Hn;if(!Array.isArray(r))throw new TypeError("`methodNames` must be an array of strings");for(const e of r)if(!Hn.includes(e))throw typeof e!="string"?new TypeError("`methodNames` element must be a string"):new Error(`${e} is not Emittery method`);return r}const Ce=r=>r===At||r===Tt;function kt(r,e,t){if(Ce(e))try{St=!0,r.emit(e,t)}finally{St=!1}}let Rt=class Un{static mixin(e,t){return t=Vn(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 Un}),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 Dr;const{env:n}=(t=globalThis.process)!=null?t:{env:{}};return n.DEBUG==="emittery"||n.DEBUG==="*"||Dr}static set isDebugEnabled(e){Dr=e}constructor(e={}){var t;te.set(this,new Set),pe.set(this,new Map),Q.set(this,new Map),Q.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=(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=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){(Un.isDebugEnabled||this.debug.enabled)&&this.debug.logger(e,this.debug.name,t,n)}on(e,t){It(t),e=Array.isArray(e)?e:[e];for(const n of e){Oe(n);let i=Me(this,n);i||(i=new Set,pe.get(this).set(n,i)),i.add(t),this.logIfDebugEnabled("subscribe",n,void 0),Ce(n)||kt(this,At,{eventName:n,listener:t})}return this.off.bind(this,e,t)}off(e,t){It(t),e=Array.isArray(e)?e:[e];for(const n of e){Oe(n);const i=Me(this,n);i&&(i.delete(t),i.size===0&&pe.get(this).delete(n)),this.logIfDebugEnabled("unsubscribe",n,void 0),Ce(n)||kt(this,Tt,{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)Oe(t);return jn(this,e)}async emit(e,t){var n;if(Oe(e),Ce(e)&&!St)throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`");this.logIfDebugEnabled("emit",e,t),fs(this,e,t);const i=(n=Me(this,e))!=null?n:new Set,o=te.get(this),s=[...i],a=Ce(e)?[]:[...o];await Gn,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(Oe(e),Ce(e)&&!St)throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`");this.logIfDebugEnabled("emitSerial",e,t);const i=(n=Me(this,e))!=null?n:new Set,o=te.get(this),s=[...i],a=[...o];await Gn;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 It(e),this.logIfDebugEnabled("subscribeAny",void 0,void 0),te.get(this).add(e),kt(this,At,{listener:e}),this.offAny.bind(this,e)}anyEvent(){return jn(this)}offAny(e){It(e),this.logIfDebugEnabled("unsubscribeAny",void 0,void 0),kt(this,Tt,{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=Me(this,t);n&&n.clear();const i=Ze(this,t);if(i){for(const o of i)o.finish();i.clear()}}else{te.get(this).clear();for(const[n,i]of pe.get(this).entries())i.clear(),pe.get(this).delete(n);for(const[n,i]of Q.get(this).entries()){for(const o of i)o.finish();i.clear(),Q.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=Me(this,u))==null?void 0:t.size)!=null?n:0)+((o=(i=Ze(this,u))==null?void 0:i.size)!=null?o:0)+((a=(s=Ze(this))==null?void 0:s.size)!=null?a:0);continue}typeof u<"u"&&Oe(u),c+=te.get(this).size;for(const f of pe.get(this).values())c+=f.size;for(const f of Q.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=Vn(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 Hn=Object.getOwnPropertyNames(Rt.prototype).filter(r=>r!=="constructor");Object.defineProperty(Rt,"listenerAdded",{value:At,writable:!1,enumerable:!0,configurable:!1}),Object.defineProperty(Rt,"listenerRemoved",{value:Tt,writable:!1,enumerable:!0,configurable:!1});function ds(r){return r.onAny&&r.emit}function hs(r){return r.prototype.onAny&&r.prototype.emit}let ms=0;async function ps(r,e,t){const n=hs(r)?new Rt:{},i=ms++;return Object.getOwnPropertyNames(r.prototype).forEach(o=>{n[o]=(...s)=>xt(e,U.FORWARD,o,s,t)}),n.terminate=async(...o)=>{const s=await xt(e,U.TERMINATE,"",o,t);return delete Et[i],e.terminate(),n.workerContext.worker=void 0,s},n.workerContext={id:i,worker:e,resolvers:t},Et[i]=n,n}async function gs(r,e){const t=new Map;let n;const i=await ls(r,e,t,(o,s)=>{n?.emit&&n?.emit(o,s)});return n=await ps(r,i,t),n}async function ys(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}`;Fe(r,await e.instance[t](...n??[]))}const Yn=me("registeredWorkers",{});function bs(r,e){e.workerId=r,Cr()&&(Yn[e.workerId]=e)}function ws(r,e){if(!r.args)throw"Missing className while initializing worker";const[t,n]=r.args,i=Yn[t];if(i)e.instance=new i(r.args.slice(1));else throw`unknown worker class ${t}`;Je(n,Pe),ds(e.instance)&&e.instance.onAny((o,s)=>{Fe({type:U.EVENT},{name:o,data:s})}),Fe(r,typeof e.instance!==void 0)}async function vs(r,e){const{args:t}=r;if(!e.instance)throw"instance not initialized";let n;e.instance.terminate&&(n=await e.instance.terminate(...t??[])),Fe(r,n)}function xs(r){if(!r.args)throw"Missing globals while syncing";Je(r.args[0],Pe),Fe(r,{})}function Es(){const r={};onmessage=async e=>{const t=e.data;switch(t.type){case U.INIT:ws(t,r);break;case U.FORWARD:ys(t,r);break;case U.TERMINATE:vs(t,r);break;case U.GLOBALS_SYNC:xs(t);break}}}Cr()&&Es();const qn='(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',Qn=typeof self<"u"&&self.Blob&&new Blob(["(self.URL || self.webkitURL).revokeObjectURL(self.location.href);",qn],{type:"text/javascript;charset=utf-8"});function _s(r){let e;try{if(e=Qn&&(self.URL||self.webkitURL).createObjectURL(Qn),!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(qn),{name:r?.name})}}class Xn{check(){return typeof globalThis.MediaStreamTrackProcessor<"u"&&typeof globalThis.VideoTrackGenerator<"u"}}bs("IsSupportedWorkerized",Xn);async function As(){return new Promise(async(r,e)=>{!Ss()&&(await Jn()||Kn())?r():e("Your browser does not support the MediaStreamTrack API for Insertable Streams of Media.")})}function Kn(){return self.MediaStreamTrackProcessor!==void 0&&self.MediaStreamTrackGenerator!==void 0||Ts()}function Ts(){return[self.ReadableStream,self.WritableStream,self.MediaStream,self.OffscreenCanvas,self.VideoFrame,self.AudioContext,self.AudioWorkletNode].filter(r=>r===void 0).length===0}function Ss(){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 Jn(){return gs(Xn,_s).then(async r=>{const e=await r.check();return await r.terminate(),e}).catch(()=>!1)}const re=new WeakMap,ge=new WeakMap,X=new WeakMap,Pt=Symbol("anyProducer"),Zn=Promise.resolve(),Ft=Symbol("listenerAdded"),Ot=Symbol("listenerRemoved");let Mt=!1,Br=!1;const Ct=r=>typeof r=="string"||typeof r=="symbol"||typeof r=="number";function De(r){if(!Ct(r))throw new TypeError("`eventName` must be a string, symbol, or number")}function Dt(r){if(typeof r!="function")throw new TypeError("listener must be a function")}function Be(r,e){const t=ge.get(r);if(t.has(e))return t.get(e)}function et(r,e){const t=Ct(e)?e:Pt,n=X.get(r);if(n.has(t))return n.get(t)}function Is(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(Pt)){const i=Promise.all([e,t]);for(const o of n.get(Pt))o.enqueue(i)}}function ei(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=et(r,s);a||(a=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=et(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 ti(r){if(r===void 0)return ri;if(!Array.isArray(r))throw new TypeError("`methodNames` must be an array of strings");for(const e of r)if(!ri.includes(e))throw typeof e!="string"?new TypeError("`methodNames` element must be a string"):new Error(`${e} is not Emittery method`);return r}const Le=r=>r===Ft||r===Ot;function Bt(r,e,t){if(Le(e))try{Mt=!0,r.emit(e,t)}finally{Mt=!1}}let ze=class Nn{static mixin(e,t){return t=ti(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 Nn}),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 Br;const{env:e}=globalThis.process??{env:{}};return e.DEBUG==="emittery"||e.DEBUG==="*"||Br}static set isDebugEnabled(e){Br=e}constructor(e={}){re.set(this,new Set),ge.set(this,new Map),X.set(this,new Map),X.get(this).set(Pt,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=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){(Nn.isDebugEnabled||this.debug.enabled)&&this.debug.logger(e,this.debug.name,t,n)}on(e,t,{signal:n}={}){Dt(t),e=Array.isArray(e)?e:[e];for(const o of e){De(o);let s=Be(this,o);s||(s=new Set,ge.get(this).set(o,s)),s.add(t),this.logIfDebugEnabled("subscribe",o,void 0),Le(o)||Bt(this,Ft,{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){Dt(t),e=Array.isArray(e)?e:[e];for(const n of e){De(n);const i=Be(this,n);i&&(i.delete(t),i.size===0&&ge.get(this).delete(n)),this.logIfDebugEnabled("unsubscribe",n,void 0),Le(n)||Bt(this,Ot,{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)De(t);return ei(this,e)}async emit(e,t){if(De(e),Le(e)&&!Mt)throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`");this.logIfDebugEnabled("emit",e,t),Is(this,e,t);const n=Be(this,e)??new Set,i=re.get(this),o=[...n],s=Le(e)?[]:[...i];await Zn,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(De(e),Le(e)&&!Mt)throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`");this.logIfDebugEnabled("emitSerial",e,t);const n=Be(this,e)??new Set,i=re.get(this),o=[...n],s=[...i];await Zn;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}={}){Dt(e),this.logIfDebugEnabled("subscribeAny",void 0,void 0),re.get(this).add(e),Bt(this,Ft,{listener:e});const n=()=>{this.offAny(e),t?.removeEventListener("abort",n)};return t?.addEventListener("abort",n,{once:!0}),t?.aborted&&n(),n}anyEvent(){return ei(this)}offAny(e){Dt(e),this.logIfDebugEnabled("unsubscribeAny",void 0,void 0),Bt(this,Ot,{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),Ct(t)){const n=Be(this,t);n&&n.clear();const i=et(this,t);if(i){for(const o of i)o.finish();i.clear()}}else{re.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){e=Array.isArray(e)?e:[e];let t=0;for(const n of e){if(Ct(n)){t+=re.get(this).size+(Be(this,n)?.size??0)+(et(this,n)?.size??0)+(et(this)?.size??0);continue}n!==void 0&&De(n),t+=re.get(this).size;for(const i of ge.get(this).values())t+=i.size;for(const i of X.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=ti(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 ri=Object.getOwnPropertyNames(ze.prototype).filter(r=>r!=="constructor");Object.defineProperty(ze,"listenerAdded",{value:Ft,writable:!1,enumerable:!0,configurable:!1}),Object.defineProperty(ze,"listenerRemoved",{value:Ot,writable:!1,enumerable:!0,configurable:!1});var ks=Object.defineProperty,Rs=(r,e,t)=>e in r?ks(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Ps=(r,e,t)=>(Rs(r,e+"",t),t);const Fs="hlg.tokbox.com/prod/logging/vcp_webrtc",Os="https://",Ms=1e4,P=[];for(let r=0;r<256;++r)P.push((r+256).toString(16).slice(1));function Cs(r,e=0){return(P[r[e+0]]+P[r[e+1]]+P[r[e+2]]+P[r[e+3]]+"-"+P[r[e+4]]+P[r[e+5]]+"-"+P[r[e+6]]+P[r[e+7]]+"-"+P[r[e+8]]+P[r[e+9]]+"-"+P[r[e+10]]+P[r[e+11]]+P[r[e+12]]+P[r[e+13]]+P[r[e+14]]+P[r[e+15]]).toLowerCase()}const Ds=new Uint8Array(16);function Bs(){return crypto.getRandomValues(Ds)}function Ls(r,e,t){return crypto.randomUUID?crypto.randomUUID():zs(r)}function zs(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:Bs();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,Cs(s)}function Lr(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 ne=Lr("globals",{});var ye=(r=>(r.INIT="INIT",r.FORWARD="FORWARD",r.TERMINATE="TERMINATE",r.GLOBALS_SYNC="GLOBALS_SYNC",r))(ye||{});function ni(r){return[ImageBitmap,ReadableStream,WritableStream].some(e=>r instanceof e)}let Us=0;function Ns(r,e,t,n,i){const o=Us++;return r.postMessage({id:o,type:e,functionName:t,args:n},n.filter(s=>ni(s))),new Promise(s=>{i?.set(o,s)})}function tt(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=Lr("workerized",{});function oi(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}async function $s(){if(oi())tt({type:ye.GLOBALS_SYNC},ne);else{const r=[];for(const e in ii){const{worker:t,resolvers:n}=ii[e].workerContext;t&&r.push(Ns(t,ye.GLOBALS_SYNC,"",[ne],n))}await Promise.all(r)}}function Lt(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]=[],Lt(r[t],e[t])):typeof r[t]=="object"?(e[t]={},Lt(r[t],e[t])):e[t]=r[t]}async function Ws(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}`;tt(r,await e.instance[t](...n??[]))}const Gs=Lr("registeredWorkers",{});function js(r,e){if(!r.args)throw"Missing className while initializing worker";const[t,n]=r.args,i=Gs[t];if(i)e.instance=new i(r.args.slice(1));else throw`unknown worker class ${t}`;Lt(n,ne),tt(r,typeof e.instance!==void 0)}async function Vs(r,e){const{args:t}=r;if(!e.instance)throw"instance not initialized";let n;e.instance.terminate&&(n=await e.instance.terminate(...t??[])),tt(r,n)}function Hs(r){if(!r.args)throw"Missing globals while syncing";Lt(r.args[0],ne),tt(r,{})}function Ys(){const r={};onmessage=async e=>{const t=e.data;switch(t.type){case ye.INIT:js(t,r);break;case ye.FORWARD:Ws(t,r);break;case ye.TERMINATE:Vs(t,r);break;case ye.GLOBALS_SYNC:Hs(t);break}}}oi()&&Ys();function qs(r,e){return ne[r]||(ne[r]=e),[()=>ne[r],async t=>{ne[r]=t,await $s()}]}function Qs(r,e){return qs(r,e)}const[Xs,Ks]=Qs("metadata");function Js(r){Ks(r)}function zt(){return Xs()}class zr{constructor(e,t){Ps(this,"uuid"),this.config=e,this.uuid=t??Ls()}async send(e){var t,n,i;const{appId:o,sourceType:s}=(t=zt())!=null?t:{};if(!o||!s)return"metadata missing";const a=new AbortController,c=setTimeout(()=>a.abort(),Ms);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=zt().proxyUrl)!=null?e:Os;return t+=(t.at(-1)==="/"?"":"/")+Fs,t}getHeaders(){return{"Content-Type":"application/json"}}buildReport(e){const t=zt();return{guid:this.uuid,...e,applicationId:t.appId,timestamp:Date.now(),proxyUrl:t.proxyUrl,source:t.sourceType}}}const Ut="3.0.4",Ur=class{};Ur.updates={transformer_new:"New transformer",transformer_null:"Null transformer"},Ur.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 be=Ur;function Zs(r){return typeof r=="object"&&r!==null&&"message"in r&&typeof r.message=="string"}function ea(r){if(Zs(r))return r;try{return new Error(JSON.stringify(r))}catch{return new Error(String(r))}}function Nr(r){return ea(r).message}class ta{constructor(e,t){this.config=e,this.frameTransformedCount=0,this.frameFromSourceCount=0,this.startAt=0,this.reporter=new zr(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 si=(r=>(r.FPS_DROP="fps_drop",r))(si||{}),ai=(r=>(r.start="start",r.transform="transform",r.flush="flush",r))(ai||{}),Nt=(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))(Nt||{});const ra=500,na=.8;class ia extends ze{constructor(e,t){super(),this.reporter_=new zr,this.reporterQos_=new ta({loggingIntervalFrameCount:ra,report:{version:Ut}}),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:be.errors.transformer_start,variation:"Error",error:Nr(t)});const n={eventMetaData:{transformerIndex:this.index_},error:t,function:"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:be.errors.transformer_transform,variation:"Error",error:Nr(n)});const i={eventMetaData:{transformerIndex:this.index_},error:n,function:"transform"};this.emit("error",i)}if(this.trackExpectedRate_!=-1&&this.trackExpectedRate_*na>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:be.errors.transformer_flush,variation:"Error",error:Nr(t)});const n={eventMetaData:{transformerIndex:this.index_},error:t,function:"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:Ut,action:"MediaTransformer",transformerType:this.transformerType_,...e})}reportQos(e=!1){this.reporterQos_.config={...this.reporterQos_.config},this.reporterQos_.onFrameTransformed({version:Ut,action:"MediaTransformer",transformerType:this.transformerType_,videoWidth:this.videoWidth_,videoHeight:this.videoHeight_},e)}}class oa extends ze{constructor(e){super(),this.transformers_=[],this.trackExpectedRate_=-1;for(let t=0;t<e.length;t++){let n=new ia(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")}).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")})}catch{this.emit("pipelineInfo","pipeline_started_with_error"),this.destroy();return}this.emit("pipelineInfo","pipeline_started"),console.log("[Pipeline] Pipeline started.")}async destroy(){console.log("[Pipeline] Destroying Pipeline.");for(let e of this.transformers_)e.stop()}}class ci extends ze{constructor(){super(),this.reporter_=new zr,this.trackExpectedRate_=-1,this.report({variation:"Create"})}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()}transformInternal(){return new Promise(async(e,t)=>{if(!this.transformers_||this.transformers_.length===0){this.report({message:be.errors.transformer_none,variation:"Error"}),t("[MediaProcessor] Need to set transformers.");return}if(!this.readable_){this.report({variation:"Error",message:be.errors.readable_null}),t("[MediaProcessor] Readable is null.");return}if(!this.writable_){this.report({variation:"Error",message:be.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 oa(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=Nt.pipeline_restarted:i==="pipeline_started_with_error"&&(i=Nt.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)})})}setTransformers(e){return this.report({variation:"Update",message:be.updates.transformer_new}),this.transformers_=e,this.readable_&&this.writable_?this.transformInternal():Promise.resolve()}destroy(){return new Promise(async e=>{this.pipeline_&&this.pipeline_.destroy(),this.report({variation:"Delete"}),e()})}report(e){this.reporter_.send({version:Ut,action:"MediaProcessor",...e})}isTrack(e){return"kind"in e}}class sa{constructor({kind:e}){if(e=="video"){const t=document.createElement("canvas"),n=t.getContext("2d",{desynchronized:!0}),i=t.captureStream().getVideoTracks()[0];return i.writable=new WritableStream({write(o){t.width=o.displayWidth,t.height=o.displayHeight,n.drawImage(o,0,0,t.width,t.height),o.close(),typeof i.requestFrame=="function"&&i.requestFrame()}}),i}else if(e=="audio"){const t=new AudioContext,n=t.createMediaStreamDestination(),[i]=n.stream.getAudioTracks();return i.writable=new WritableStream({async start(o){this.arrays=[];function s(){registerProcessor("mstg-shim",class extends AudioWorkletProcessor{constructor(){super(),this.arrays=[],this.arrayOffset=0,this.port.onmessage=({data:a})=>this.arrays.push(a),this.emptyArray=new Float32Array(0)}process(a,[[c]]){for(let u=0;u<c.length;u++)(!this.array||this.arrayOffset>=this.array.length)&&(this.array=this.arrays.shift()||this.emptyArray,this.arrayOffset=0),c[u]=this.array[this.arrayOffset++]||0;return!0}})}return await t.audioWorklet.addModule(`data:text/javascript,(${s.toString()})()`),this.node=new AudioWorkletNode(t,"mstg-shim"),this.node.connect(n),i},write(o){const s=new Float32Array(o.numberOfFrames*o.numberOfChannels);o.copyTo(s,{planeIndex:0}),this.node.port.postMessage(s,[s.buffer]),o.close()}}),i}}}function aa(){return self.MediaStreamTrackGenerator?self.MediaStreamTrackGenerator:sa}class ca{constructor(e){const t=e.track??e;t.kind=="video"?this.readable=new ReadableStream({async start(n){t.addEventListener("ended",()=>{try{n.close()}catch{}},{once:!0}),this.video=document.createElement("video"),this.video.setAttribute("playsinline",""),this.video.srcObject=new MediaStream([t]),await Promise.all([this.video.play(),new Promise(i=>this.video.onloadedmetadata=i)]),this.track=t,this.canvas=new OffscreenCanvas(this.video.videoWidth,this.video.videoHeight),this.ctx=this.canvas.getContext("2d",{desynchronized:!0}),this.t1=performance.now()},async pull(n){if(t.readyState=="ended"){try{n.close()}catch{}return}const i=t.getSettings().frameRate||30;for(;performance.now()-this.t1<1e3/i;)if(await new Promise(o=>requestAnimationFrame(o)),t.readyState=="ended"){try{n.close()}catch{}return}this.canvas.width=this.video.videoWidth,this.canvas.height=this.video.videoHeight,this.t1=performance.now(),this.ctx.drawImage(this.video,0,0),n.enqueue(new VideoFrame(this.canvas,{timestamp:this.t1}))}}):t.kind=="audio"&&(this.readable=new ReadableStream({async start(n){t.addEventListener("ended",()=>{try{n.close()}catch{}},{once:!0}),this.ac=new AudioContext,this.arrays=[];function i(){registerProcessor("mstp-shim",class extends AudioWorkletProcessor{process(o){return this.port.postMessage(o),!0}})}await this.ac.audioWorklet.addModule(`data:text/javascript,(${i.toString()})()`),this.node=new AudioWorkletNode(this.ac,"mstp-shim"),this.ac.createMediaStreamSource(new MediaStream([t])).connect(this.node),this.node.port.addEventListener("message",({data:o})=>o[0][0]&&this.arrays.push(o))},async pull(n){if(t.readyState=="ended"){try{n.close()}catch{}return}for(;!this.arrays.length;)if(await new Promise(s=>this.node.port.onmessage=s),t.readyState=="ended"){try{n.close()}catch{}return}const[i]=this.arrays.shift(),o=new Float32Array(i.reduce((s,a)=>s+a.length,0));i.reduce((s,a)=>(o.set(a,s),s+a.length),0),n.enqueue(new AudioData({format:"f32-planar",sampleRate:this.ac.sampleRate,numberOfFrames:i[0].length,numberOfChannels:i.length,timestamp:this.ac.currentTime*1e6|0,data:o,transfer:[o.buffer]}))}}))}}function ua(){return self.MediaStreamTrackProcessor?self.MediaStreamTrackProcessor:ca}class la{constructor(){this.processor_=null,this.generator_=null}init(e){return new Promise((t,n)=>{try{const i=ua();this.processor_=new i(e)}catch(i){console.log(`[InsertableStreamHelper] MediaStreamTrackProcessor failed: ${i}`),n(i)}try{const i=aa();e.kind==="audio"?this.generator_=new i({kind:"audio"}):e.kind==="video"?this.generator_=new i({kind:"video"}):n("kind not supported")}catch(i){console.log(`[InsertableStreamHelper] MediaStreamTrackGenerator failed: ${i}`),n(i)}t()})}getReadable(){return this.processor_.readable}getWriteable(){return this.generator_.writable}getProccesorTrack(){return this.generator_}}class fa{constructor(e){this.mediaProcessor_=e}async setTrack(e){if(!(this.mediaProcessor_ instanceof ci)&&await Jn()){if(e.kind==="audio")throw Error("Cannot process audio tracks inside a web worker when passing a track to transform");return await this.mediaProcessor_.transform(e)}if(Kn()){const t=new la;return await t.init(e),await this.mediaProcessor_.transform(t.getReadable(),t.getWriteable()),t.getProccesorTrack()}throw Error("MediaStreamTrack API for Insertable Streams of Media is not supported")}destroy(){return new Promise((e,t)=>{this.mediaProcessor_?this.mediaProcessor_.destroy().then(()=>{e()}).catch(n=>{t(n)}):t("no processor")})}}var rt=(r=>(r.Low="Low",r.High="High",r))(rt||{}),ui=(r=>(r.BackgroundBlur="BackgroundBlur",r.VirtualBackground="VirtualBackground",r.VideoBackground="VideoBackground",r.SilhouetteBlur="SilhouetteBlur",r))(ui||{}),$t=(r=>(r.FAST="FAST",r.PRECISE="PRECISE",r))($t||{}),nt=(r=>(r.CANVAS="CANVAS",r.WEBGL="WEBGL",r))(nt||{});const da=async()=>WebAssembly.validate(new Uint8Array([0,97,115,109,1,0,0,0,1,5,1,96,0,1,123,3,2,1,0,10,10,1,8,0,65,0,253,15,253,98,11]));async function ha(){const{wasm:r,insertableStreams:e,simd:t,webgl:n}=await li();if(!r.supported)throw r.message;if(!e.supported)throw e.message;if(!t.supported)throw t.message;if(!n.supported)throw n.message}async function li(){const r={wasm:{supported:typeof WebAssembly=="object"&&typeof WebAssembly.instantiate=="function",message:"Your browser does not support WebAssembly features."},simd:{supported:await da(),message:"Your browser does not support simd features."},insertableStreams:{supported:!0},gpu:{message:"Your browser does not support gpu features.",supported:!0},webgl:ma(),performance:fi()};try{await As()}catch(e){r.insertableStreams.supported=!1,r.insertableStreams.message=e}return r}function ma(){if(!OffscreenCanvas)return{supported:!1,message:"Your browser does not support offscreen canvas"};const e=new OffscreenCanvas(0,0).getContext("webgl2");if(e){const t=e?.getExtension("WEBGL_lose_context");t&&t.loseContext()}else return{supported:!1,message:"Your browser does not support webgl 2"};return{supported:!0}}function fi(){const e=new OffscreenCanvas(0,0).getContext("webgl2",{failIfMajorPerformanceCaveat:!0});if(e){const t=e?.getExtension("WEBGL_lose_context");t&&t.loseContext()}else return{supported:!1,message:"Your hardware does not perform good enough to run the library efficiently"};return{supported:!0}}const ie=new WeakMap,we=new WeakMap,K=new WeakMap,Wt=Symbol("anyProducer"),di=Promise.resolve(),Gt=Symbol("listenerAdded"),jt=Symbol("listenerRemoved");let Vt=!1,$r=!1;const Ht=r=>typeof r=="string"||typeof r=="symbol"||typeof r=="number";function Ue(r){if(!Ht(r))throw new TypeError("`eventName` must be a string, symbol, or number")}function Yt(r){if(typeof r!="function")throw new TypeError("listener must be a function")}function Ne(r,e){const t=we.get(r);if(t.has(e))return t.get(e)}function it(r,e){const t=Ht(e)?e:Wt,n=K.get(r);if(n.has(t))return n.get(t)}function hi(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(Wt)){const i=Promise.all([e,t]);for(const o of n.get(Wt))o.enqueue(i)}}function mi(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=it(r,s);a||(a=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=it(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 pi(r){if(r===void 0)return gi;if(!Array.isArray(r))throw new TypeError("`methodNames` must be an array of strings");for(const e of r)if(!gi.includes(e))throw typeof e!="string"?new TypeError("`methodNames` element must be a string"):new Error(`${e} is not Emittery method`);return r}const ve=r=>r===Gt||r===jt;function qt(r,e,t){if(ve(e))try{Vt=!0,r.emit(e,t)}finally{Vt=!1}}let ot=class $n{static mixin(e,t){return t=pi(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 $n}),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 $r;const{env:e}=globalThis.process??{env:{}};return e.DEBUG==="emittery"||e.DEBUG==="*"||$r}static set isDebugEnabled(e){$r=e}constructor(e={}){ie.set(this,new Set),we.set(this,new Map),K.set(this,new Map),K.get(this).set(Wt,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=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){($n.isDebugEnabled||this.debug.enabled)&&this.debug.logger(e,this.debug.name,t,n)}on(e,t,{signal:n}={}){Yt(t),e=Array.isArray(e)?e:[e];for(const o of e){Ue(o);let s=Ne(this,o);s||(s=new Set,we.get(this).set(o,s)),s.add(t),this.logIfDebugEnabled("subscribe",o,void 0),ve(o)||qt(this,Gt,{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){Yt(t),e=Array.isArray(e)?e:[e];for(const n of e){Ue(n);const i=Ne(this,n);i&&(i.delete(t),i.size===0&&we.get(this).delete(n)),this.logIfDebugEnabled("unsubscribe",n,void 0),ve(n)||qt(this,jt,{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)Ue(t);return mi(this,e)}async emit(e,t){if(Ue(e),ve(e)&&!Vt)throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`");this.logIfDebugEnabled("emit",e,t),hi(this,e,t);const n=Ne(this,e)??new Set,i=ie.get(this),o=[...n],s=ve(e)?[]:[...i];await di,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(Ue(e),ve(e)&&!Vt)throw new TypeError("`eventName` cannot be meta event `listenerAdded` or `listenerRemoved`");this.logIfDebugEnabled("emitSerial",e,t),hi(this,e,t);const n=Ne(this,e)??new Set,i=ie.get(this),o=[...n],s=ve(e)?[]:[...i];await di;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}={}){Yt(e),this.logIfDebugEnabled("subscribeAny",void 0,void 0),ie.get(this).add(e),qt(this,Gt,{listener:e});const n=()=>{this.offAny(e),t?.removeEventListener("abort",n)};return t?.addEventListener("abort",n,{once:!0}),t?.aborted&&n(),n}anyEvent(){return mi(this)}offAny(e){Yt(e),this.logIfDebugEnabled("unsubscribeAny",void 0,void 0),qt(this,jt,{listener:e}),ie.get(this).delete(e)}clearListeners(e){e=Array.isArray(e)?e:[e];for(const t of e)if(this.logIfDebugEnabled("clear",t,void 0),Ht(t)){const n=N