@cloudflare/realtimekit-virtual-background 0.0.2 → 0.0.3-staging.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,9 +14,9 @@
14
14
  <br />
15
15
  <a href="https://demo.realtime.cloudflare.com/">View Demo</a>
16
16
  ·
17
- <a href="https://dyte.io/contact">Report Bug</a>
17
+ <a href="https://community.cloudflare.com/c/developers/cloudflare-realtime/101">Report Bug</a>
18
18
  ·
19
- <a href="https://dyte.io/contact">Request Feature</a>
19
+ <a href="https://community.cloudflare.com/c/developers/cloudflare-realtime/101">Request Feature</a>
20
20
  </p>
21
21
  </p>
22
22
 
@@ -57,6 +57,13 @@ If you are using the `rtk-meeting` component directly and prefer abstraction ove
57
57
  npm install @cloudflare/realtimekit-virtual-background
58
58
  ```
59
59
 
60
+ ### Run the example
61
+
62
+ 1. Run `npm install` in this repository.
63
+ 2. Replace `YOUR_AUTH_TOKEN` in `index.html` with a valid RealtimeKit participant token.
64
+ 3. Run `npm run dev` and open `http://localhost:3002`.
65
+ 4. Enable the camera from the setup screen to try the virtual background.
66
+
60
67
  <!-- USAGE EXAMPLES -->
61
68
  ## Usage
62
69
 
@@ -119,4 +126,4 @@ const videoBackgroundTransformer = await RealtimeKitVideoBackgroundTransformer.i
119
126
  targetFps: 35,
120
127
  }
121
128
  });
122
- ```
129
+ ```
package/dist/index.cjs.js CHANGED
@@ -228,4 +228,4 @@
228
228
  * https://github.com/lancedikson/bowser
229
229
  * MIT License | (c) Dustin Diaz 2012-2015
230
230
  * MIT License | (c) Denis Demchenko 2015-2019
231
- */class Lt{static getParser(r,e=!1){if(typeof r!="string")throw new Error("UserAgent should be a string");return new mt(r,e)}static parse(r){return new mt(r).getResult()}static get BROWSER_MAP(){return _t}static get ENGINE_MAP(){return ue}static get OS_MAP(){return q}static get PLATFORMS_MAP(){return N}}function it(){return Lt.getParser(window.navigator.userAgent)}function gt(t,r,e,i,s,c){const f=i.getContext("2d"),[p,l]=ve[e.inputResolution],m=p*l,h=new ImageData(p,l),u=document.createElement("canvas");u.width=p,u.height=l;const w=u.getContext("2d",{willReadFrequently:!0}),E=s._getInputMemoryOffset()/4,_=s._getOutputMemoryOffset()/4;let R,b=null;const T=pt("https://assets.dyte.io/backgrounds/blur.jpg");async function U(){b=await vt(t.htmlElement),r.type!=="none"&&C(),r.type!=="none"&&B(),await x()}function W(A){R=A}function D(){}function C(){if(w.drawImage(b,0,0,t.width,t.height,0,0,p,l),e.model==="meet"||e.model==="mlkit"){const A=w.getImageData(0,0,p,l);for(let L=0;L<m;L++)s.HEAPF32[E+L*3]=A.data[L*4]/255,s.HEAPF32[E+L*3+1]=A.data[L*4+1]/255,s.HEAPF32[E+L*3+2]=A.data[L*4+2]/255}}function B(){s._runInference();for(let A=0;A<m;A++)if(e.model==="meet"){const L=s.HEAPF32[_+A*2],re=s.HEAPF32[_+A*2+1],F=Math.max(L,re),J=Math.exp(L-F),Z=Math.exp(re-F);h.data[A*4+3]=255*Z/(J+Z)}else if(e.model==="mlkit"){const L=s.HEAPF32[_+A];h.data[A*4+3]=255*L}w.putImageData(h,0,0)}async function x(){f.globalCompositeOperation="copy",f.filter="none",f.drawImage(b,0,0),R!=null&&R.smoothSegmentationMask&&(r.type==="blur"?f.filter="blur(8px)":r.type==="image"&&(f.filter="blur(4px)")),r.type!=="none"&&(f.globalCompositeOperation="destination-in",f.filter="none",H()),r.type==="blur"?await j():G()}function G(){f.globalCompositeOperation="destination-over",f.drawImage(r.backgroundImage,0,0)}function H(){f.drawImage(u,0,0,p,l,0,0,t.width,t.height)}async function j(){if(f.globalCompositeOperation="destination-over",it().getBrowserName()==="Safari"){const A=await T;f.drawImage(A,0,0)}else f.filter=`blur(${r.blurLength}px)`,f.drawImage(b,0,0)}return{render:U,updatePostProcessingConfig:W,cleanUp:D}}var Q,pe;const ut=class extends lt{constructor(e){super();me(this,Q,void 0);me(this,pe,void 0);ae(this,Q,e)}static async init(e){return new ut(e)}async createStaticBackgroundImageVideoMiddleware(e){const i=await pt(e);return async({canvas:s,WorkerTimers:c})=>{const f=`RUN_${Date.now()}_${Math.round(Math.random()*100)}`;ae(this,pe,f);const p=await this.createCameraVideoElement(O(this,Q).meeting.self.rawVideoTrack);s.width=p.width,s.height=p.height;const m=(O(this,Q).segmentationConfig.pipeline==="canvas2dCpu"?gt:ht)({htmlElement:p,width:O(this,Q).meeting.self.rawVideoTrack.getSettings().width,height:O(this,Q).meeting.self.rawVideoTrack.getSettings().height},{type:"image",backgroundImage:i},O(this,Q).segmentationConfig,s,O(this,Q).tflite,c);m.updatePostProcessingConfig(O(this,Q).postProcessingConfig);const h=1e3/O(this,Q).segmentationConfig.targetFps,u=async()=>{if(f!==O(this,pe)||!O(this,Q).meeting.self.videoEnabled){await m.cleanUp();return}const w=performance.now();await m.render(),c.setTimeout(u,Math.max(0,h-(performance.now()-w)))};c.setTimeout(()=>{u()},0)}}destruct(){ae(this,pe,null)}};let ot=ut;Q=new WeakMap,pe=new WeakMap;var $,he;const ct=class extends lt{constructor(e){super();me(this,$,void 0);me(this,he,void 0);ae(this,$,e)}static async init(e){return new ct(e)}async createBackgroundBlurVideoMiddleware(e){return async({canvas:i,WorkerTimers:s})=>{const c=`RUN_${Date.now()}_${Math.round(Math.random()*100)}`;ae(this,he,c);const f=await this.createCameraVideoElement(O(this,$).meeting.self.rawVideoTrack);i.width=f.width,i.height=f.height;const l=(O(this,$).segmentationConfig.pipeline==="canvas2dCpu"?gt:ht)({htmlElement:f,width:O(this,$).meeting.self.rawVideoTrack.getSettings().width,height:O(this,$).meeting.self.rawVideoTrack.getSettings().height},{type:"blur",blurLength:e},O(this,$).segmentationConfig,i,O(this,$).tflite,s);l.updatePostProcessingConfig(O(this,$).postProcessingConfig);const m=1e3/O(this,$).segmentationConfig.targetFps,h=async()=>{if(c!==O(this,he)||!O(this,$).meeting.self.videoEnabled){await l.cleanUp();return}const u=performance.now();await l.render(),s.setTimeout(h,Math.max(0,m-(performance.now()-u)))};s.setTimeout(()=>{h()},0)}}async destruct(){ae(this,he,null)}};let st=ct;$=new WeakMap,he=new WeakMap;var Dt=(()=>{var t="https://assets.dyte.io/virtual-bg/";return function(r){r=r||{};var e=typeof r!="undefined"?r:{},i,s;e.ready=new Promise(function(n,o){i=n,s=o});var c=Object.assign({},e),f="./this.program",p=(n,o)=>{throw o},l=!0,m="";function h(n){return e.locateFile?e.locateFile(n,m):m+n}var u;typeof document!="undefined"&&document.currentScript&&(m=document.currentScript.src),m=t,m.indexOf("blob:")!==0?m=m.substr(0,m.replace(/[?#].*/,"").lastIndexOf("/")+1):m="";var w=e.print||console.log.bind(console),E=e.printErr||console.warn.bind(console);Object.assign(e,c),c=null,e.arguments&&e.arguments,e.thisProgram&&(f=e.thisProgram),e.quit&&(p=e.quit);var _;e.wasmBinary&&(_=e.wasmBinary);var R=e.noExitRuntime||!0;typeof WebAssembly!="object"&&z("no native wasm support detected");var b,T=!1,U=typeof TextDecoder!="undefined"?new TextDecoder("utf8"):void 0;function W(n,o,d){for(var v=o+d,y=o;n[y]&&!(y>=v);)++y;if(y-o>16&&n.buffer&&U)return U.decode(n.subarray(o,y));for(var M="";o<y;){var g=n[o++];if(!(g&128)){M+=String.fromCharCode(g);continue}var S=n[o++]&63;if((g&224)==192){M+=String.fromCharCode((g&31)<<6|S);continue}var P=n[o++]&63;if((g&240)==224?g=(g&15)<<12|S<<6|P:g=(g&7)<<18|S<<12|P<<6|n[o++]&63,g<65536)M+=String.fromCharCode(g);else{var K=g-65536;M+=String.fromCharCode(55296|K>>10,56320|K&1023)}}return M}var D,C,B,x;function G(n){D=n,e.HEAP8=C=new Int8Array(n),e.HEAP16=new Int16Array(n),e.HEAP32=new Int32Array(n),e.HEAPU8=B=new Uint8Array(n),e.HEAPU16=new Uint16Array(n),e.HEAPU32=x=new Uint32Array(n),e.HEAPF32=new Float32Array(n),e.HEAPF64=new Float64Array(n)}e.INITIAL_MEMORY;var H=[],j=[],A=[];function L(){return R}function re(){if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)Z(e.preRun.shift());fe(H)}function F(){fe(j)}function J(){if(e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;)ee(e.postRun.shift());fe(A)}function Z(n){H.unshift(n)}function Y(n){j.unshift(n)}function ee(n){A.unshift(n)}var V=0,X=null;function be(n){V++,e.monitorRunDependencies&&e.monitorRunDependencies(V)}function Fe(n){if(V--,e.monitorRunDependencies&&e.monitorRunDependencies(V),V==0&&X){var o=X;X=null,o()}}function z(n){e.onAbort&&e.onAbort(n),n="Aborted("+n+")",E(n),T=!0,n+=". Build with -sASSERTIONS for more info.";var o=new WebAssembly.RuntimeError(n);throw s(o),o}var Te="data:application/octet-stream;base64,";function we(n){return n.startsWith(Te)}var I;I="tflite.wasm",we(I)||(I=h(I));function ye(n){try{if(n==I&&_)return new Uint8Array(_);throw"both async and sync fetching of the wasm failed"}catch(o){z(o)}}function xe(){return!_&&l&&typeof fetch=="function"?fetch(I,{credentials:"same-origin"}).then(function(n){if(!n.ok)throw"failed to load wasm binary file at '"+I+"'";return n.arrayBuffer()}).catch(function(){return ye(I)}):Promise.resolve().then(function(){return ye(I)})}function Ce(){var n={env:Se,wasi_snapshot_preview1:Se};function o(g,S){var P=g.exports;e.asm=P,b=e.asm.memory,G(b.buffer),e.asm.__indirect_function_table,Y(e.asm.__wasm_call_ctors),Fe()}be();function d(g){o(g.instance)}function v(g){return xe().then(function(S){return WebAssembly.instantiate(S,n)}).then(function(S){return S}).then(g,function(S){E("failed to asynchronously prepare wasm: "+S),z(S)})}function y(){return!_&&typeof WebAssembly.instantiateStreaming=="function"&&!we(I)&&typeof fetch=="function"?fetch(I,{credentials:"same-origin"}).then(function(g){var S=WebAssembly.instantiateStreaming(g,n);return S.then(d,function(P){return E("wasm streaming compile failed: "+P),E("falling back to ArrayBuffer instantiation"),v(d)})}):v(d)}if(e.instantiateWasm)try{var M=e.instantiateWasm(n,o);return M}catch(g){E("Module.instantiateWasm callback failed with error: "+g),s(g)}return y().catch(s),{}}function Be(n){this.name="ExitStatus",this.message="Program terminated with exit("+n+")",this.status=n}function fe(n){for(;n.length>0;)n.shift()(e)}function Pe(n){}var Ee="To use dlopen, you need enable dynamic linking, see https://github.com/emscripten-core/emscripten/wiki/Linking";function ke(n,o){z(Ee)}function Oe(n,o){z(Ee)}var Ue=!0;function Ie(){return Ue}function Le(n,o,d,v,y,M){return-52}function De(n,o,d,v,y,M){}function je(){z("")}function Ne(){return Date.now()}function Re(){return 2147483648}function We(){return Re()}var Me;Me=()=>performance.now();function He(n,o,d){B.copyWithin(n,o,o+d)}function Ve(n){try{return b.grow(n-D.byteLength+65535>>>16),G(b.buffer),1}catch{}}function Ge(n){var o=B.length;n=n>>>0;var d=Re();if(n>d)return!1;let v=(P,K)=>P+(K-P%K)%K;for(var y=1;y<=4;y*=2){var M=o*(1+.2/y);M=Math.min(M,n+100663296);var g=Math.min(d,v(Math.max(n,M),65536)),S=Ve(g);if(S)return!0}return!1}var de={};function Xe(){return f||"./this.program"}function te(){if(!te.strings){var n=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",o={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:n,_:Xe()};for(var d in de)de[d]===void 0?delete o[d]:o[d]=de[d];var v=[];for(var d in o)v.push(d+"="+o[d]);te.strings=v}return te.strings}function ze(n,o,d){for(var v=0;v<n.length;++v)C[o++>>0]=n.charCodeAt(v);d||(C[o>>0]=0)}function qe(n,o){var d=0;return te().forEach(function(v,y){var M=o+d;x[n+y*4>>2]=M,ze(v,M),d+=v.length+1}),0}function Ye(n,o){var d=te();x[n>>2]=d.length;var v=0;return d.forEach(function(y){v+=y.length+1}),x[o>>2]=v,0}function Ke(n){L()||(e.onExit&&e.onExit(n),T=!0),p(n,new Be(n))}function Qe(n,o){Ke(n)}var $e=Qe;function Je(n){return 52}function Ze(n,o,d,v,y){return 70}var et=[null,[],[]];function tt(n,o){var d=et[n];o===0||o===10?((n===1?w:E)(W(d,0)),d.length=0):d.push(o)}function rt(n,o,d,v){for(var y=0,M=0;M<d;M++){var g=x[o>>2],S=x[o+4>>2];o+=8;for(var P=0;P<S;P++)tt(n,B[g+P]);y+=S}return x[v>>2]=y,0}function nt(){if(typeof crypto=="object"&&typeof crypto.getRandomValues=="function"){var n=new Uint8Array(1);return()=>(crypto.getRandomValues(n),n[0])}else return()=>z("randomDevice")}function oe(n,o){oe.randomDevice||(oe.randomDevice=nt());for(var d=0;d<o;d++)C[n+d>>0]=oe.randomDevice();return 0}var Se={_dlinit:Pe,_dlopen_js:ke,_dlsym_js:Oe,_emscripten_get_now_is_monotonic:Ie,_mmap_js:Le,_munmap_js:De,abort:je,emscripten_date_now:Ne,emscripten_get_heap_max:We,emscripten_get_now:Me,emscripten_memcpy_big:He,emscripten_resize_heap:Ge,environ_get:qe,environ_sizes_get:Ye,exit:$e,fd_close:Je,fd_seek:Ze,fd_write:rt,getentropy:oe};Ce(),e.___wasm_call_ctors=function(){return(e.___wasm_call_ctors=e.asm.__wasm_call_ctors).apply(null,arguments)},e._getModelBufferMemoryOffset=function(){return(e._getModelBufferMemoryOffset=e.asm.getModelBufferMemoryOffset).apply(null,arguments)},e._getInputMemoryOffset=function(){return(e._getInputMemoryOffset=e.asm.getInputMemoryOffset).apply(null,arguments)},e._getInputHeight=function(){return(e._getInputHeight=e.asm.getInputHeight).apply(null,arguments)},e._getInputWidth=function(){return(e._getInputWidth=e.asm.getInputWidth).apply(null,arguments)},e._getInputChannelCount=function(){return(e._getInputChannelCount=e.asm.getInputChannelCount).apply(null,arguments)},e._getOutputMemoryOffset=function(){return(e._getOutputMemoryOffset=e.asm.getOutputMemoryOffset).apply(null,arguments)},e._getOutputHeight=function(){return(e._getOutputHeight=e.asm.getOutputHeight).apply(null,arguments)},e._getOutputWidth=function(){return(e._getOutputWidth=e.asm.getOutputWidth).apply(null,arguments)},e._getOutputChannelCount=function(){return(e._getOutputChannelCount=e.asm.getOutputChannelCount).apply(null,arguments)},e._loadModel=function(){return(e._loadModel=e.asm.loadModel).apply(null,arguments)},e._runInference=function(){return(e._runInference=e.asm.runInference).apply(null,arguments)},e._malloc=function(){return(e._malloc=e.asm.malloc).apply(null,arguments)},e.___errno_location=function(){return(e.___errno_location=e.asm.__errno_location).apply(null,arguments)},e.___dl_seterr=function(){return(e.___dl_seterr=e.asm.__dl_seterr).apply(null,arguments)},e.stackSave=function(){return(e.stackSave=e.asm.stackSave).apply(null,arguments)},e.stackRestore=function(){return(e.stackRestore=e.asm.stackRestore).apply(null,arguments)},e.stackAlloc=function(){return(e.stackAlloc=e.asm.stackAlloc).apply(null,arguments)},e.dynCall_jjj=function(){return(e.dynCall_jjj=e.asm.dynCall_jjj).apply(null,arguments)},e.dynCall_jiii=function(){return(e.dynCall_jiii=e.asm.dynCall_jiii).apply(null,arguments)},e.dynCall_iiiijj=function(){return(e.dynCall_iiiijj=e.asm.dynCall_iiiijj).apply(null,arguments)},e.dynCall_viijj=function(){return(e.dynCall_viijj=e.asm.dynCall_viijj).apply(null,arguments)},e.dynCall_viiijjj=function(){return(e.dynCall_viiijjj=e.asm.dynCall_viiijjj).apply(null,arguments)},e.dynCall_iijjiiii=function(){return(e.dynCall_iijjiiii=e.asm.dynCall_iijjiiii).apply(null,arguments)},e.dynCall_jiji=function(){return(e.dynCall_jiji=e.asm.dynCall_jiji).apply(null,arguments)};var se;X=function n(){se||Ae(),se||(X=n)};function Ae(n){if(V>0||(re(),V>0))return;function o(){se||(se=!0,e.calledRun=!0,!T&&(F(),i(e),e.onRuntimeInitialized&&e.onRuntimeInitialized(),J()))}e.setStatus?(e.setStatus("Running..."),setTimeout(function(){setTimeout(function(){e.setStatus("")},1),o()},1)):o()}if(e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);e.preInit.length>0;)e.preInit.pop()();return Ae(),r.ready}})(),jt=(()=>{var t="https://assets.dyte.io/virtual-bg/";return function(r){r=r||{};var e=typeof r!="undefined"?r:{},i,s;e.ready=new Promise(function(n,o){i=n,s=o});var c=Object.assign({},e),f="./this.program",p=(n,o)=>{throw o},l=!0,m="";function h(n){return e.locateFile?e.locateFile(n,m):m+n}var u;typeof document!="undefined"&&document.currentScript&&(m=document.currentScript.src),m=t,m.indexOf("blob:")!==0?m=m.substr(0,m.replace(/[?#].*/,"").lastIndexOf("/")+1):m="";var w=e.print||console.log.bind(console),E=e.printErr||console.warn.bind(console);Object.assign(e,c),c=null,e.arguments&&e.arguments,e.thisProgram&&(f=e.thisProgram),e.quit&&(p=e.quit);var _;e.wasmBinary&&(_=e.wasmBinary);var R=e.noExitRuntime||!0;typeof WebAssembly!="object"&&z("no native wasm support detected");var b,T=!1,U=typeof TextDecoder!="undefined"?new TextDecoder("utf8"):void 0;function W(n,o,d){for(var v=o+d,y=o;n[y]&&!(y>=v);)++y;if(y-o>16&&n.buffer&&U)return U.decode(n.subarray(o,y));for(var M="";o<y;){var g=n[o++];if(!(g&128)){M+=String.fromCharCode(g);continue}var S=n[o++]&63;if((g&224)==192){M+=String.fromCharCode((g&31)<<6|S);continue}var P=n[o++]&63;if((g&240)==224?g=(g&15)<<12|S<<6|P:g=(g&7)<<18|S<<12|P<<6|n[o++]&63,g<65536)M+=String.fromCharCode(g);else{var K=g-65536;M+=String.fromCharCode(55296|K>>10,56320|K&1023)}}return M}var D,C,B,x;function G(n){D=n,e.HEAP8=C=new Int8Array(n),e.HEAP16=new Int16Array(n),e.HEAP32=new Int32Array(n),e.HEAPU8=B=new Uint8Array(n),e.HEAPU16=new Uint16Array(n),e.HEAPU32=x=new Uint32Array(n),e.HEAPF32=new Float32Array(n),e.HEAPF64=new Float64Array(n)}e.INITIAL_MEMORY;var H=[],j=[],A=[];function L(){return R}function re(){if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)Z(e.preRun.shift());fe(H)}function F(){fe(j)}function J(){if(e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;)ee(e.postRun.shift());fe(A)}function Z(n){H.unshift(n)}function Y(n){j.unshift(n)}function ee(n){A.unshift(n)}var V=0,X=null;function be(n){V++,e.monitorRunDependencies&&e.monitorRunDependencies(V)}function Fe(n){if(V--,e.monitorRunDependencies&&e.monitorRunDependencies(V),V==0&&X){var o=X;X=null,o()}}function z(n){e.onAbort&&e.onAbort(n),n="Aborted("+n+")",E(n),T=!0,n+=". Build with -sASSERTIONS for more info.";var o=new WebAssembly.RuntimeError(n);throw s(o),o}var Te="data:application/octet-stream;base64,";function we(n){return n.startsWith(Te)}var I;I="tflite-simd.wasm",we(I)||(I=h(I));function ye(n){try{if(n==I&&_)return new Uint8Array(_);throw"both async and sync fetching of the wasm failed"}catch(o){z(o)}}function xe(){return!_&&l&&typeof fetch=="function"?fetch(I,{credentials:"same-origin"}).then(function(n){if(!n.ok)throw"failed to load wasm binary file at '"+I+"'";return n.arrayBuffer()}).catch(function(){return ye(I)}):Promise.resolve().then(function(){return ye(I)})}function Ce(){var n={env:Se,wasi_snapshot_preview1:Se};function o(g,S){var P=g.exports;e.asm=P,b=e.asm.memory,G(b.buffer),e.asm.__indirect_function_table,Y(e.asm.__wasm_call_ctors),Fe()}be();function d(g){o(g.instance)}function v(g){return xe().then(function(S){return WebAssembly.instantiate(S,n)}).then(function(S){return S}).then(g,function(S){E("failed to asynchronously prepare wasm: "+S),z(S)})}function y(){return!_&&typeof WebAssembly.instantiateStreaming=="function"&&!we(I)&&typeof fetch=="function"?fetch(I,{credentials:"same-origin"}).then(function(g){var S=WebAssembly.instantiateStreaming(g,n);return S.then(d,function(P){return E("wasm streaming compile failed: "+P),E("falling back to ArrayBuffer instantiation"),v(d)})}):v(d)}if(e.instantiateWasm)try{var M=e.instantiateWasm(n,o);return M}catch(g){E("Module.instantiateWasm callback failed with error: "+g),s(g)}return y().catch(s),{}}function Be(n){this.name="ExitStatus",this.message="Program terminated with exit("+n+")",this.status=n}function fe(n){for(;n.length>0;)n.shift()(e)}function Pe(n){}var Ee="To use dlopen, you need enable dynamic linking, see https://github.com/emscripten-core/emscripten/wiki/Linking";function ke(n,o){z(Ee)}function Oe(n,o){z(Ee)}var Ue=!0;function Ie(){return Ue}function Le(n,o,d,v,y,M){return-52}function De(n,o,d,v,y,M){}function je(){z("")}function Ne(){return Date.now()}function Re(){return 2147483648}function We(){return Re()}var Me;Me=()=>performance.now();function He(n,o,d){B.copyWithin(n,o,o+d)}function Ve(n){try{return b.grow(n-D.byteLength+65535>>>16),G(b.buffer),1}catch{}}function Ge(n){var o=B.length;n=n>>>0;var d=Re();if(n>d)return!1;let v=(P,K)=>P+(K-P%K)%K;for(var y=1;y<=4;y*=2){var M=o*(1+.2/y);M=Math.min(M,n+100663296);var g=Math.min(d,v(Math.max(n,M),65536)),S=Ve(g);if(S)return!0}return!1}var de={};function Xe(){return f||"./this.program"}function te(){if(!te.strings){var n=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",o={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:n,_:Xe()};for(var d in de)de[d]===void 0?delete o[d]:o[d]=de[d];var v=[];for(var d in o)v.push(d+"="+o[d]);te.strings=v}return te.strings}function ze(n,o,d){for(var v=0;v<n.length;++v)C[o++>>0]=n.charCodeAt(v);d||(C[o>>0]=0)}function qe(n,o){var d=0;return te().forEach(function(v,y){var M=o+d;x[n+y*4>>2]=M,ze(v,M),d+=v.length+1}),0}function Ye(n,o){var d=te();x[n>>2]=d.length;var v=0;return d.forEach(function(y){v+=y.length+1}),x[o>>2]=v,0}function Ke(n){L()||(e.onExit&&e.onExit(n),T=!0),p(n,new Be(n))}function Qe(n,o){Ke(n)}var $e=Qe;function Je(n){return 52}function Ze(n,o,d,v,y){return 70}var et=[null,[],[]];function tt(n,o){var d=et[n];o===0||o===10?((n===1?w:E)(W(d,0)),d.length=0):d.push(o)}function rt(n,o,d,v){for(var y=0,M=0;M<d;M++){var g=x[o>>2],S=x[o+4>>2];o+=8;for(var P=0;P<S;P++)tt(n,B[g+P]);y+=S}return x[v>>2]=y,0}function nt(){if(typeof crypto=="object"&&typeof crypto.getRandomValues=="function"){var n=new Uint8Array(1);return()=>(crypto.getRandomValues(n),n[0])}else return()=>z("randomDevice")}function oe(n,o){oe.randomDevice||(oe.randomDevice=nt());for(var d=0;d<o;d++)C[n+d>>0]=oe.randomDevice();return 0}var Se={_dlinit:Pe,_dlopen_js:ke,_dlsym_js:Oe,_emscripten_get_now_is_monotonic:Ie,_mmap_js:Le,_munmap_js:De,abort:je,emscripten_date_now:Ne,emscripten_get_heap_max:We,emscripten_get_now:Me,emscripten_memcpy_big:He,emscripten_resize_heap:Ge,environ_get:qe,environ_sizes_get:Ye,exit:$e,fd_close:Je,fd_seek:Ze,fd_write:rt,getentropy:oe};Ce(),e.___wasm_call_ctors=function(){return(e.___wasm_call_ctors=e.asm.__wasm_call_ctors).apply(null,arguments)},e._getModelBufferMemoryOffset=function(){return(e._getModelBufferMemoryOffset=e.asm.getModelBufferMemoryOffset).apply(null,arguments)},e._getInputMemoryOffset=function(){return(e._getInputMemoryOffset=e.asm.getInputMemoryOffset).apply(null,arguments)},e._getInputHeight=function(){return(e._getInputHeight=e.asm.getInputHeight).apply(null,arguments)},e._getInputWidth=function(){return(e._getInputWidth=e.asm.getInputWidth).apply(null,arguments)},e._getInputChannelCount=function(){return(e._getInputChannelCount=e.asm.getInputChannelCount).apply(null,arguments)},e._getOutputMemoryOffset=function(){return(e._getOutputMemoryOffset=e.asm.getOutputMemoryOffset).apply(null,arguments)},e._getOutputHeight=function(){return(e._getOutputHeight=e.asm.getOutputHeight).apply(null,arguments)},e._getOutputWidth=function(){return(e._getOutputWidth=e.asm.getOutputWidth).apply(null,arguments)},e._getOutputChannelCount=function(){return(e._getOutputChannelCount=e.asm.getOutputChannelCount).apply(null,arguments)},e._loadModel=function(){return(e._loadModel=e.asm.loadModel).apply(null,arguments)},e._runInference=function(){return(e._runInference=e.asm.runInference).apply(null,arguments)},e._malloc=function(){return(e._malloc=e.asm.malloc).apply(null,arguments)},e.___errno_location=function(){return(e.___errno_location=e.asm.__errno_location).apply(null,arguments)},e.___dl_seterr=function(){return(e.___dl_seterr=e.asm.__dl_seterr).apply(null,arguments)},e.stackSave=function(){return(e.stackSave=e.asm.stackSave).apply(null,arguments)},e.stackRestore=function(){return(e.stackRestore=e.asm.stackRestore).apply(null,arguments)},e.stackAlloc=function(){return(e.stackAlloc=e.asm.stackAlloc).apply(null,arguments)},e.dynCall_jjj=function(){return(e.dynCall_jjj=e.asm.dynCall_jjj).apply(null,arguments)},e.dynCall_jiii=function(){return(e.dynCall_jiii=e.asm.dynCall_jiii).apply(null,arguments)},e.dynCall_iiiijj=function(){return(e.dynCall_iiiijj=e.asm.dynCall_iiiijj).apply(null,arguments)},e.dynCall_viijj=function(){return(e.dynCall_viijj=e.asm.dynCall_viijj).apply(null,arguments)},e.dynCall_viiijjj=function(){return(e.dynCall_viiijjj=e.asm.dynCall_viiijjj).apply(null,arguments)},e.dynCall_iijjiiii=function(){return(e.dynCall_iijjiiii=e.asm.dynCall_iijjiiii).apply(null,arguments)},e.dynCall_jiji=function(){return(e.dynCall_jiji=e.asm.dynCall_jiji).apply(null,arguments)};var se;X=function n(){se||Ae(),se||(X=n)};function Ae(n){if(V>0||(re(),V>0))return;function o(){se||(se=!0,e.calledRun=!0,!T&&(F(),i(e),e.onRuntimeInitialized&&e.onRuntimeInitialized(),J()))}e.setStatus?(e.setStatus("Running..."),setTimeout(function(){setTimeout(function(){e.setStatus("")},1),o()},1)):o()}if(e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);e.preInit.length>0;)e.preInit.pop()();return Ae(),r.ready}})();async function Nt(t){let r=null,e=null,i=null,s=!1;async function c(){r=await Dt();try{e=await jt(),s=!0,t.backend="wasmSimd"}catch(p){console.warn("Failed to create TFLite SIMD WebAssembly module.",p)}}await c();async function f(){if(!r||s&&!e||!s&&t.backend==="wasmSimd"||t.model!=="meet"&&t.model!=="mlkit")return;i=null;const p=t.backend==="wasmSimd"?e:r;if(!p)throw new Error(`TFLite backend unavailable: ${t.backend}`);const l=bt(t.model,t.inputResolution),h=await(await fetch(`https://dyte-plugins.s3.ap-south-1.amazonaws.com/tf-assets/models/${l}.tflite`)).arrayBuffer(),u=p._getModelBufferMemoryOffset();p.HEAPU8.set(new Uint8Array(h),u),p._loadModel(h.byteLength),i=p}return await f(),{tflite:i,isSIMDSupported:s}}var _e,ge;const ft=class{constructor(r,e){me(this,_e,void 0);me(this,ge,void 0);ae(this,_e,r),ae(this,ge,e)}static async init({meeting:r,segmentationConfig:e,postProcessingConfig:i}){this.isSupported()||console.error("Initialising it in an unsupported environment, the middleware might not work"),window.addEventListener("error",l=>{var m;!((m=l.filename)!=null&&m.includes("localhost"))&&l.lineno!==0&&console.error("RealtimeKitVideoBackgroundTransformer::UnhandledError",l.error)}),window.addEventListener("unhandledrejection",l=>{console.error("RealtimeKitVideoBackgroundTransformer::UnhandledRejection",l.reason)});const s={model:"mlkit",backend:"wasmSimd",inputResolution:"256x256",pipeline:"webgl2",targetFps:35,deferInputResizing:!0,...e||{}};it().getEngineName()==="WebKit"&&(s.pipeline="canvas2dCpu");const f={smoothSegmentationMask:!0,jointBilateralFilter:{sigmaSpace:1,sigmaColor:.1},coverage:[.5,.75],lightWrapping:.3,blendMode:"screen",...i||{}};await r.self.setVideoMiddlewareGlobalConfig({disablePerFrameCanvasRendering:!0});const{tflite:p}=await Nt(s);return new ft(await ot.init({meeting:r,segmentationConfig:s,postProcessingConfig:f,tflite:p}),await st.init({meeting:r,segmentationConfig:s,postProcessingConfig:f,tflite:p}))}static isSupported(){var e;let r=!1;try{const i=it(),s=document.createElement("canvas"),c=s.getContext("webgl2",{})||s.getContext("webgl",{}),f=+((e=i.getBrowserVersion())==null?void 0:e.split(".")[0]);if(!c||i.getOSName()==="iOS"||i.getBrowserName()==="Safari"&&f<17)return!1;r=!0}catch{r=!1}return r}async createStaticBackgroundVideoMiddleware(r){return await O(this,_e).createStaticBackgroundImageVideoMiddleware(r)}async createBackgroundBlurVideoMiddleware(r=50){return O(this,ge).createBackgroundBlurVideoMiddleware(r)}destruct(){O(this,_e).destruct(),O(this,ge).destruct()}};let at=ft;_e=new WeakMap,ge=new WeakMap;module.exports=at;
231
+ */class Lt{static getParser(r,e=!1){if(typeof r!="string")throw new Error("UserAgent should be a string");return new mt(r,e)}static parse(r){return new mt(r).getResult()}static get BROWSER_MAP(){return _t}static get ENGINE_MAP(){return ue}static get OS_MAP(){return q}static get PLATFORMS_MAP(){return N}}function it(){return Lt.getParser(window.navigator.userAgent)}function gt(t,r,e,i,s,c){const f=i.getContext("2d"),[p,l]=ve[e.inputResolution],m=p*l,h=new ImageData(p,l),u=document.createElement("canvas");u.width=p,u.height=l;const w=u.getContext("2d",{willReadFrequently:!0}),E=s._getInputMemoryOffset()/4,_=s._getOutputMemoryOffset()/4;let R,b=null;const T=pt("https://rtk-assets.realtime.cloudflare.com/backgrounds/blur.jpg");async function U(){b=await vt(t.htmlElement),r.type!=="none"&&C(),r.type!=="none"&&B(),await x()}function W(A){R=A}function D(){}function C(){if(w.drawImage(b,0,0,t.width,t.height,0,0,p,l),e.model==="meet"||e.model==="mlkit"){const A=w.getImageData(0,0,p,l);for(let L=0;L<m;L++)s.HEAPF32[E+L*3]=A.data[L*4]/255,s.HEAPF32[E+L*3+1]=A.data[L*4+1]/255,s.HEAPF32[E+L*3+2]=A.data[L*4+2]/255}}function B(){s._runInference();for(let A=0;A<m;A++)if(e.model==="meet"){const L=s.HEAPF32[_+A*2],re=s.HEAPF32[_+A*2+1],F=Math.max(L,re),J=Math.exp(L-F),Z=Math.exp(re-F);h.data[A*4+3]=255*Z/(J+Z)}else if(e.model==="mlkit"){const L=s.HEAPF32[_+A];h.data[A*4+3]=255*L}w.putImageData(h,0,0)}async function x(){f.globalCompositeOperation="copy",f.filter="none",f.drawImage(b,0,0),R!=null&&R.smoothSegmentationMask&&(r.type==="blur"?f.filter="blur(8px)":r.type==="image"&&(f.filter="blur(4px)")),r.type!=="none"&&(f.globalCompositeOperation="destination-in",f.filter="none",H()),r.type==="blur"?await j():G()}function G(){f.globalCompositeOperation="destination-over",f.drawImage(r.backgroundImage,0,0)}function H(){f.drawImage(u,0,0,p,l,0,0,t.width,t.height)}async function j(){if(f.globalCompositeOperation="destination-over",it().getBrowserName()==="Safari"){const A=await T;f.drawImage(A,0,0)}else f.filter=`blur(${r.blurLength}px)`,f.drawImage(b,0,0)}return{render:U,updatePostProcessingConfig:W,cleanUp:D}}var Q,pe;const ut=class extends lt{constructor(e){super();me(this,Q,void 0);me(this,pe,void 0);ae(this,Q,e)}static async init(e){return new ut(e)}async createStaticBackgroundImageVideoMiddleware(e){const i=await pt(e);return async({canvas:s,WorkerTimers:c})=>{const f=`RUN_${Date.now()}_${Math.round(Math.random()*100)}`;ae(this,pe,f);const p=await this.createCameraVideoElement(O(this,Q).meeting.self.rawVideoTrack);s.width=p.width,s.height=p.height;const m=(O(this,Q).segmentationConfig.pipeline==="canvas2dCpu"?gt:ht)({htmlElement:p,width:O(this,Q).meeting.self.rawVideoTrack.getSettings().width,height:O(this,Q).meeting.self.rawVideoTrack.getSettings().height},{type:"image",backgroundImage:i},O(this,Q).segmentationConfig,s,O(this,Q).tflite,c);m.updatePostProcessingConfig(O(this,Q).postProcessingConfig);const h=1e3/O(this,Q).segmentationConfig.targetFps,u=async()=>{if(f!==O(this,pe)||!O(this,Q).meeting.self.videoEnabled){await m.cleanUp();return}const w=performance.now();await m.render(),c.setTimeout(u,Math.max(0,h-(performance.now()-w)))};c.setTimeout(()=>{u()},0)}}destruct(){ae(this,pe,null)}};let ot=ut;Q=new WeakMap,pe=new WeakMap;var $,he;const ct=class extends lt{constructor(e){super();me(this,$,void 0);me(this,he,void 0);ae(this,$,e)}static async init(e){return new ct(e)}async createBackgroundBlurVideoMiddleware(e){return async({canvas:i,WorkerTimers:s})=>{const c=`RUN_${Date.now()}_${Math.round(Math.random()*100)}`;ae(this,he,c);const f=await this.createCameraVideoElement(O(this,$).meeting.self.rawVideoTrack);i.width=f.width,i.height=f.height;const l=(O(this,$).segmentationConfig.pipeline==="canvas2dCpu"?gt:ht)({htmlElement:f,width:O(this,$).meeting.self.rawVideoTrack.getSettings().width,height:O(this,$).meeting.self.rawVideoTrack.getSettings().height},{type:"blur",blurLength:e},O(this,$).segmentationConfig,i,O(this,$).tflite,s);l.updatePostProcessingConfig(O(this,$).postProcessingConfig);const m=1e3/O(this,$).segmentationConfig.targetFps,h=async()=>{if(c!==O(this,he)||!O(this,$).meeting.self.videoEnabled){await l.cleanUp();return}const u=performance.now();await l.render(),s.setTimeout(h,Math.max(0,m-(performance.now()-u)))};s.setTimeout(()=>{h()},0)}}async destruct(){ae(this,he,null)}};let st=ct;$=new WeakMap,he=new WeakMap;var Dt=(()=>{var t="https://rtk-assets.realtime.cloudflare.com/virtual-bg/";return function(r){r=r||{};var e=typeof r!="undefined"?r:{},i,s;e.ready=new Promise(function(n,o){i=n,s=o});var c=Object.assign({},e),f="./this.program",p=(n,o)=>{throw o},l=!0,m="";function h(n){return e.locateFile?e.locateFile(n,m):m+n}var u;typeof document!="undefined"&&document.currentScript&&(m=document.currentScript.src),m=t,m.indexOf("blob:")!==0?m=m.substr(0,m.replace(/[?#].*/,"").lastIndexOf("/")+1):m="";var w=e.print||console.log.bind(console),E=e.printErr||console.warn.bind(console);Object.assign(e,c),c=null,e.arguments&&e.arguments,e.thisProgram&&(f=e.thisProgram),e.quit&&(p=e.quit);var _;e.wasmBinary&&(_=e.wasmBinary);var R=e.noExitRuntime||!0;typeof WebAssembly!="object"&&z("no native wasm support detected");var b,T=!1,U=typeof TextDecoder!="undefined"?new TextDecoder("utf8"):void 0;function W(n,o,d){for(var v=o+d,y=o;n[y]&&!(y>=v);)++y;if(y-o>16&&n.buffer&&U)return U.decode(n.subarray(o,y));for(var M="";o<y;){var g=n[o++];if(!(g&128)){M+=String.fromCharCode(g);continue}var S=n[o++]&63;if((g&224)==192){M+=String.fromCharCode((g&31)<<6|S);continue}var P=n[o++]&63;if((g&240)==224?g=(g&15)<<12|S<<6|P:g=(g&7)<<18|S<<12|P<<6|n[o++]&63,g<65536)M+=String.fromCharCode(g);else{var K=g-65536;M+=String.fromCharCode(55296|K>>10,56320|K&1023)}}return M}var D,C,B,x;function G(n){D=n,e.HEAP8=C=new Int8Array(n),e.HEAP16=new Int16Array(n),e.HEAP32=new Int32Array(n),e.HEAPU8=B=new Uint8Array(n),e.HEAPU16=new Uint16Array(n),e.HEAPU32=x=new Uint32Array(n),e.HEAPF32=new Float32Array(n),e.HEAPF64=new Float64Array(n)}e.INITIAL_MEMORY;var H=[],j=[],A=[];function L(){return R}function re(){if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)Z(e.preRun.shift());fe(H)}function F(){fe(j)}function J(){if(e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;)ee(e.postRun.shift());fe(A)}function Z(n){H.unshift(n)}function Y(n){j.unshift(n)}function ee(n){A.unshift(n)}var V=0,X=null;function be(n){V++,e.monitorRunDependencies&&e.monitorRunDependencies(V)}function Fe(n){if(V--,e.monitorRunDependencies&&e.monitorRunDependencies(V),V==0&&X){var o=X;X=null,o()}}function z(n){e.onAbort&&e.onAbort(n),n="Aborted("+n+")",E(n),T=!0,n+=". Build with -sASSERTIONS for more info.";var o=new WebAssembly.RuntimeError(n);throw s(o),o}var Te="data:application/octet-stream;base64,";function we(n){return n.startsWith(Te)}var I;I="tflite.wasm",we(I)||(I=h(I));function ye(n){try{if(n==I&&_)return new Uint8Array(_);throw"both async and sync fetching of the wasm failed"}catch(o){z(o)}}function xe(){return!_&&l&&typeof fetch=="function"?fetch(I,{credentials:"same-origin"}).then(function(n){if(!n.ok)throw"failed to load wasm binary file at '"+I+"'";return n.arrayBuffer()}).catch(function(){return ye(I)}):Promise.resolve().then(function(){return ye(I)})}function Ce(){var n={env:Se,wasi_snapshot_preview1:Se};function o(g,S){var P=g.exports;e.asm=P,b=e.asm.memory,G(b.buffer),e.asm.__indirect_function_table,Y(e.asm.__wasm_call_ctors),Fe()}be();function d(g){o(g.instance)}function v(g){return xe().then(function(S){return WebAssembly.instantiate(S,n)}).then(function(S){return S}).then(g,function(S){E("failed to asynchronously prepare wasm: "+S),z(S)})}function y(){return!_&&typeof WebAssembly.instantiateStreaming=="function"&&!we(I)&&typeof fetch=="function"?fetch(I,{credentials:"same-origin"}).then(function(g){var S=WebAssembly.instantiateStreaming(g,n);return S.then(d,function(P){return E("wasm streaming compile failed: "+P),E("falling back to ArrayBuffer instantiation"),v(d)})}):v(d)}if(e.instantiateWasm)try{var M=e.instantiateWasm(n,o);return M}catch(g){E("Module.instantiateWasm callback failed with error: "+g),s(g)}return y().catch(s),{}}function Be(n){this.name="ExitStatus",this.message="Program terminated with exit("+n+")",this.status=n}function fe(n){for(;n.length>0;)n.shift()(e)}function Pe(n){}var Ee="To use dlopen, you need enable dynamic linking, see https://github.com/emscripten-core/emscripten/wiki/Linking";function ke(n,o){z(Ee)}function Oe(n,o){z(Ee)}var Ue=!0;function Ie(){return Ue}function Le(n,o,d,v,y,M){return-52}function De(n,o,d,v,y,M){}function je(){z("")}function Ne(){return Date.now()}function Re(){return 2147483648}function We(){return Re()}var Me;Me=()=>performance.now();function He(n,o,d){B.copyWithin(n,o,o+d)}function Ve(n){try{return b.grow(n-D.byteLength+65535>>>16),G(b.buffer),1}catch{}}function Ge(n){var o=B.length;n=n>>>0;var d=Re();if(n>d)return!1;let v=(P,K)=>P+(K-P%K)%K;for(var y=1;y<=4;y*=2){var M=o*(1+.2/y);M=Math.min(M,n+100663296);var g=Math.min(d,v(Math.max(n,M),65536)),S=Ve(g);if(S)return!0}return!1}var de={};function Xe(){return f||"./this.program"}function te(){if(!te.strings){var n=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",o={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:n,_:Xe()};for(var d in de)de[d]===void 0?delete o[d]:o[d]=de[d];var v=[];for(var d in o)v.push(d+"="+o[d]);te.strings=v}return te.strings}function ze(n,o,d){for(var v=0;v<n.length;++v)C[o++>>0]=n.charCodeAt(v);d||(C[o>>0]=0)}function qe(n,o){var d=0;return te().forEach(function(v,y){var M=o+d;x[n+y*4>>2]=M,ze(v,M),d+=v.length+1}),0}function Ye(n,o){var d=te();x[n>>2]=d.length;var v=0;return d.forEach(function(y){v+=y.length+1}),x[o>>2]=v,0}function Ke(n){L()||(e.onExit&&e.onExit(n),T=!0),p(n,new Be(n))}function Qe(n,o){Ke(n)}var $e=Qe;function Je(n){return 52}function Ze(n,o,d,v,y){return 70}var et=[null,[],[]];function tt(n,o){var d=et[n];o===0||o===10?((n===1?w:E)(W(d,0)),d.length=0):d.push(o)}function rt(n,o,d,v){for(var y=0,M=0;M<d;M++){var g=x[o>>2],S=x[o+4>>2];o+=8;for(var P=0;P<S;P++)tt(n,B[g+P]);y+=S}return x[v>>2]=y,0}function nt(){if(typeof crypto=="object"&&typeof crypto.getRandomValues=="function"){var n=new Uint8Array(1);return()=>(crypto.getRandomValues(n),n[0])}else return()=>z("randomDevice")}function oe(n,o){oe.randomDevice||(oe.randomDevice=nt());for(var d=0;d<o;d++)C[n+d>>0]=oe.randomDevice();return 0}var Se={_dlinit:Pe,_dlopen_js:ke,_dlsym_js:Oe,_emscripten_get_now_is_monotonic:Ie,_mmap_js:Le,_munmap_js:De,abort:je,emscripten_date_now:Ne,emscripten_get_heap_max:We,emscripten_get_now:Me,emscripten_memcpy_big:He,emscripten_resize_heap:Ge,environ_get:qe,environ_sizes_get:Ye,exit:$e,fd_close:Je,fd_seek:Ze,fd_write:rt,getentropy:oe};Ce(),e.___wasm_call_ctors=function(){return(e.___wasm_call_ctors=e.asm.__wasm_call_ctors).apply(null,arguments)},e._getModelBufferMemoryOffset=function(){return(e._getModelBufferMemoryOffset=e.asm.getModelBufferMemoryOffset).apply(null,arguments)},e._getInputMemoryOffset=function(){return(e._getInputMemoryOffset=e.asm.getInputMemoryOffset).apply(null,arguments)},e._getInputHeight=function(){return(e._getInputHeight=e.asm.getInputHeight).apply(null,arguments)},e._getInputWidth=function(){return(e._getInputWidth=e.asm.getInputWidth).apply(null,arguments)},e._getInputChannelCount=function(){return(e._getInputChannelCount=e.asm.getInputChannelCount).apply(null,arguments)},e._getOutputMemoryOffset=function(){return(e._getOutputMemoryOffset=e.asm.getOutputMemoryOffset).apply(null,arguments)},e._getOutputHeight=function(){return(e._getOutputHeight=e.asm.getOutputHeight).apply(null,arguments)},e._getOutputWidth=function(){return(e._getOutputWidth=e.asm.getOutputWidth).apply(null,arguments)},e._getOutputChannelCount=function(){return(e._getOutputChannelCount=e.asm.getOutputChannelCount).apply(null,arguments)},e._loadModel=function(){return(e._loadModel=e.asm.loadModel).apply(null,arguments)},e._runInference=function(){return(e._runInference=e.asm.runInference).apply(null,arguments)},e._malloc=function(){return(e._malloc=e.asm.malloc).apply(null,arguments)},e.___errno_location=function(){return(e.___errno_location=e.asm.__errno_location).apply(null,arguments)},e.___dl_seterr=function(){return(e.___dl_seterr=e.asm.__dl_seterr).apply(null,arguments)},e.stackSave=function(){return(e.stackSave=e.asm.stackSave).apply(null,arguments)},e.stackRestore=function(){return(e.stackRestore=e.asm.stackRestore).apply(null,arguments)},e.stackAlloc=function(){return(e.stackAlloc=e.asm.stackAlloc).apply(null,arguments)},e.dynCall_jjj=function(){return(e.dynCall_jjj=e.asm.dynCall_jjj).apply(null,arguments)},e.dynCall_jiii=function(){return(e.dynCall_jiii=e.asm.dynCall_jiii).apply(null,arguments)},e.dynCall_iiiijj=function(){return(e.dynCall_iiiijj=e.asm.dynCall_iiiijj).apply(null,arguments)},e.dynCall_viijj=function(){return(e.dynCall_viijj=e.asm.dynCall_viijj).apply(null,arguments)},e.dynCall_viiijjj=function(){return(e.dynCall_viiijjj=e.asm.dynCall_viiijjj).apply(null,arguments)},e.dynCall_iijjiiii=function(){return(e.dynCall_iijjiiii=e.asm.dynCall_iijjiiii).apply(null,arguments)},e.dynCall_jiji=function(){return(e.dynCall_jiji=e.asm.dynCall_jiji).apply(null,arguments)};var se;X=function n(){se||Ae(),se||(X=n)};function Ae(n){if(V>0||(re(),V>0))return;function o(){se||(se=!0,e.calledRun=!0,!T&&(F(),i(e),e.onRuntimeInitialized&&e.onRuntimeInitialized(),J()))}e.setStatus?(e.setStatus("Running..."),setTimeout(function(){setTimeout(function(){e.setStatus("")},1),o()},1)):o()}if(e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);e.preInit.length>0;)e.preInit.pop()();return Ae(),r.ready}})(),jt=(()=>{var t="https://rtk-assets.realtime.cloudflare.com/virtual-bg/";return function(r){r=r||{};var e=typeof r!="undefined"?r:{},i,s;e.ready=new Promise(function(n,o){i=n,s=o});var c=Object.assign({},e),f="./this.program",p=(n,o)=>{throw o},l=!0,m="";function h(n){return e.locateFile?e.locateFile(n,m):m+n}var u;typeof document!="undefined"&&document.currentScript&&(m=document.currentScript.src),m=t,m.indexOf("blob:")!==0?m=m.substr(0,m.replace(/[?#].*/,"").lastIndexOf("/")+1):m="";var w=e.print||console.log.bind(console),E=e.printErr||console.warn.bind(console);Object.assign(e,c),c=null,e.arguments&&e.arguments,e.thisProgram&&(f=e.thisProgram),e.quit&&(p=e.quit);var _;e.wasmBinary&&(_=e.wasmBinary);var R=e.noExitRuntime||!0;typeof WebAssembly!="object"&&z("no native wasm support detected");var b,T=!1,U=typeof TextDecoder!="undefined"?new TextDecoder("utf8"):void 0;function W(n,o,d){for(var v=o+d,y=o;n[y]&&!(y>=v);)++y;if(y-o>16&&n.buffer&&U)return U.decode(n.subarray(o,y));for(var M="";o<y;){var g=n[o++];if(!(g&128)){M+=String.fromCharCode(g);continue}var S=n[o++]&63;if((g&224)==192){M+=String.fromCharCode((g&31)<<6|S);continue}var P=n[o++]&63;if((g&240)==224?g=(g&15)<<12|S<<6|P:g=(g&7)<<18|S<<12|P<<6|n[o++]&63,g<65536)M+=String.fromCharCode(g);else{var K=g-65536;M+=String.fromCharCode(55296|K>>10,56320|K&1023)}}return M}var D,C,B,x;function G(n){D=n,e.HEAP8=C=new Int8Array(n),e.HEAP16=new Int16Array(n),e.HEAP32=new Int32Array(n),e.HEAPU8=B=new Uint8Array(n),e.HEAPU16=new Uint16Array(n),e.HEAPU32=x=new Uint32Array(n),e.HEAPF32=new Float32Array(n),e.HEAPF64=new Float64Array(n)}e.INITIAL_MEMORY;var H=[],j=[],A=[];function L(){return R}function re(){if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)Z(e.preRun.shift());fe(H)}function F(){fe(j)}function J(){if(e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;)ee(e.postRun.shift());fe(A)}function Z(n){H.unshift(n)}function Y(n){j.unshift(n)}function ee(n){A.unshift(n)}var V=0,X=null;function be(n){V++,e.monitorRunDependencies&&e.monitorRunDependencies(V)}function Fe(n){if(V--,e.monitorRunDependencies&&e.monitorRunDependencies(V),V==0&&X){var o=X;X=null,o()}}function z(n){e.onAbort&&e.onAbort(n),n="Aborted("+n+")",E(n),T=!0,n+=". Build with -sASSERTIONS for more info.";var o=new WebAssembly.RuntimeError(n);throw s(o),o}var Te="data:application/octet-stream;base64,";function we(n){return n.startsWith(Te)}var I;I="tflite-simd.wasm",we(I)||(I=h(I));function ye(n){try{if(n==I&&_)return new Uint8Array(_);throw"both async and sync fetching of the wasm failed"}catch(o){z(o)}}function xe(){return!_&&l&&typeof fetch=="function"?fetch(I,{credentials:"same-origin"}).then(function(n){if(!n.ok)throw"failed to load wasm binary file at '"+I+"'";return n.arrayBuffer()}).catch(function(){return ye(I)}):Promise.resolve().then(function(){return ye(I)})}function Ce(){var n={env:Se,wasi_snapshot_preview1:Se};function o(g,S){var P=g.exports;e.asm=P,b=e.asm.memory,G(b.buffer),e.asm.__indirect_function_table,Y(e.asm.__wasm_call_ctors),Fe()}be();function d(g){o(g.instance)}function v(g){return xe().then(function(S){return WebAssembly.instantiate(S,n)}).then(function(S){return S}).then(g,function(S){E("failed to asynchronously prepare wasm: "+S),z(S)})}function y(){return!_&&typeof WebAssembly.instantiateStreaming=="function"&&!we(I)&&typeof fetch=="function"?fetch(I,{credentials:"same-origin"}).then(function(g){var S=WebAssembly.instantiateStreaming(g,n);return S.then(d,function(P){return E("wasm streaming compile failed: "+P),E("falling back to ArrayBuffer instantiation"),v(d)})}):v(d)}if(e.instantiateWasm)try{var M=e.instantiateWasm(n,o);return M}catch(g){E("Module.instantiateWasm callback failed with error: "+g),s(g)}return y().catch(s),{}}function Be(n){this.name="ExitStatus",this.message="Program terminated with exit("+n+")",this.status=n}function fe(n){for(;n.length>0;)n.shift()(e)}function Pe(n){}var Ee="To use dlopen, you need enable dynamic linking, see https://github.com/emscripten-core/emscripten/wiki/Linking";function ke(n,o){z(Ee)}function Oe(n,o){z(Ee)}var Ue=!0;function Ie(){return Ue}function Le(n,o,d,v,y,M){return-52}function De(n,o,d,v,y,M){}function je(){z("")}function Ne(){return Date.now()}function Re(){return 2147483648}function We(){return Re()}var Me;Me=()=>performance.now();function He(n,o,d){B.copyWithin(n,o,o+d)}function Ve(n){try{return b.grow(n-D.byteLength+65535>>>16),G(b.buffer),1}catch{}}function Ge(n){var o=B.length;n=n>>>0;var d=Re();if(n>d)return!1;let v=(P,K)=>P+(K-P%K)%K;for(var y=1;y<=4;y*=2){var M=o*(1+.2/y);M=Math.min(M,n+100663296);var g=Math.min(d,v(Math.max(n,M),65536)),S=Ve(g);if(S)return!0}return!1}var de={};function Xe(){return f||"./this.program"}function te(){if(!te.strings){var n=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",o={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:n,_:Xe()};for(var d in de)de[d]===void 0?delete o[d]:o[d]=de[d];var v=[];for(var d in o)v.push(d+"="+o[d]);te.strings=v}return te.strings}function ze(n,o,d){for(var v=0;v<n.length;++v)C[o++>>0]=n.charCodeAt(v);d||(C[o>>0]=0)}function qe(n,o){var d=0;return te().forEach(function(v,y){var M=o+d;x[n+y*4>>2]=M,ze(v,M),d+=v.length+1}),0}function Ye(n,o){var d=te();x[n>>2]=d.length;var v=0;return d.forEach(function(y){v+=y.length+1}),x[o>>2]=v,0}function Ke(n){L()||(e.onExit&&e.onExit(n),T=!0),p(n,new Be(n))}function Qe(n,o){Ke(n)}var $e=Qe;function Je(n){return 52}function Ze(n,o,d,v,y){return 70}var et=[null,[],[]];function tt(n,o){var d=et[n];o===0||o===10?((n===1?w:E)(W(d,0)),d.length=0):d.push(o)}function rt(n,o,d,v){for(var y=0,M=0;M<d;M++){var g=x[o>>2],S=x[o+4>>2];o+=8;for(var P=0;P<S;P++)tt(n,B[g+P]);y+=S}return x[v>>2]=y,0}function nt(){if(typeof crypto=="object"&&typeof crypto.getRandomValues=="function"){var n=new Uint8Array(1);return()=>(crypto.getRandomValues(n),n[0])}else return()=>z("randomDevice")}function oe(n,o){oe.randomDevice||(oe.randomDevice=nt());for(var d=0;d<o;d++)C[n+d>>0]=oe.randomDevice();return 0}var Se={_dlinit:Pe,_dlopen_js:ke,_dlsym_js:Oe,_emscripten_get_now_is_monotonic:Ie,_mmap_js:Le,_munmap_js:De,abort:je,emscripten_date_now:Ne,emscripten_get_heap_max:We,emscripten_get_now:Me,emscripten_memcpy_big:He,emscripten_resize_heap:Ge,environ_get:qe,environ_sizes_get:Ye,exit:$e,fd_close:Je,fd_seek:Ze,fd_write:rt,getentropy:oe};Ce(),e.___wasm_call_ctors=function(){return(e.___wasm_call_ctors=e.asm.__wasm_call_ctors).apply(null,arguments)},e._getModelBufferMemoryOffset=function(){return(e._getModelBufferMemoryOffset=e.asm.getModelBufferMemoryOffset).apply(null,arguments)},e._getInputMemoryOffset=function(){return(e._getInputMemoryOffset=e.asm.getInputMemoryOffset).apply(null,arguments)},e._getInputHeight=function(){return(e._getInputHeight=e.asm.getInputHeight).apply(null,arguments)},e._getInputWidth=function(){return(e._getInputWidth=e.asm.getInputWidth).apply(null,arguments)},e._getInputChannelCount=function(){return(e._getInputChannelCount=e.asm.getInputChannelCount).apply(null,arguments)},e._getOutputMemoryOffset=function(){return(e._getOutputMemoryOffset=e.asm.getOutputMemoryOffset).apply(null,arguments)},e._getOutputHeight=function(){return(e._getOutputHeight=e.asm.getOutputHeight).apply(null,arguments)},e._getOutputWidth=function(){return(e._getOutputWidth=e.asm.getOutputWidth).apply(null,arguments)},e._getOutputChannelCount=function(){return(e._getOutputChannelCount=e.asm.getOutputChannelCount).apply(null,arguments)},e._loadModel=function(){return(e._loadModel=e.asm.loadModel).apply(null,arguments)},e._runInference=function(){return(e._runInference=e.asm.runInference).apply(null,arguments)},e._malloc=function(){return(e._malloc=e.asm.malloc).apply(null,arguments)},e.___errno_location=function(){return(e.___errno_location=e.asm.__errno_location).apply(null,arguments)},e.___dl_seterr=function(){return(e.___dl_seterr=e.asm.__dl_seterr).apply(null,arguments)},e.stackSave=function(){return(e.stackSave=e.asm.stackSave).apply(null,arguments)},e.stackRestore=function(){return(e.stackRestore=e.asm.stackRestore).apply(null,arguments)},e.stackAlloc=function(){return(e.stackAlloc=e.asm.stackAlloc).apply(null,arguments)},e.dynCall_jjj=function(){return(e.dynCall_jjj=e.asm.dynCall_jjj).apply(null,arguments)},e.dynCall_jiii=function(){return(e.dynCall_jiii=e.asm.dynCall_jiii).apply(null,arguments)},e.dynCall_iiiijj=function(){return(e.dynCall_iiiijj=e.asm.dynCall_iiiijj).apply(null,arguments)},e.dynCall_viijj=function(){return(e.dynCall_viijj=e.asm.dynCall_viijj).apply(null,arguments)},e.dynCall_viiijjj=function(){return(e.dynCall_viiijjj=e.asm.dynCall_viiijjj).apply(null,arguments)},e.dynCall_iijjiiii=function(){return(e.dynCall_iijjiiii=e.asm.dynCall_iijjiiii).apply(null,arguments)},e.dynCall_jiji=function(){return(e.dynCall_jiji=e.asm.dynCall_jiji).apply(null,arguments)};var se;X=function n(){se||Ae(),se||(X=n)};function Ae(n){if(V>0||(re(),V>0))return;function o(){se||(se=!0,e.calledRun=!0,!T&&(F(),i(e),e.onRuntimeInitialized&&e.onRuntimeInitialized(),J()))}e.setStatus?(e.setStatus("Running..."),setTimeout(function(){setTimeout(function(){e.setStatus("")},1),o()},1)):o()}if(e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);e.preInit.length>0;)e.preInit.pop()();return Ae(),r.ready}})();async function Nt(t){let r=null,e=null,i=null,s=!1;async function c(){r=await Dt();try{e=await jt(),s=!0,t.backend="wasmSimd"}catch(p){console.warn("Failed to create TFLite SIMD WebAssembly module.",p)}}await c();async function f(){if(!r||s&&!e||!s&&t.backend==="wasmSimd"||t.model!=="meet"&&t.model!=="mlkit")return;i=null;const p=t.backend==="wasmSimd"?e:r;if(!p)throw new Error(`TFLite backend unavailable: ${t.backend}`);const l=bt(t.model,t.inputResolution),h=await(await fetch(`https://rtk-assets.realtime.cloudflare.com/virtual-bg/tf-assets/models/${l}.tflite`)).arrayBuffer(),u=p._getModelBufferMemoryOffset();p.HEAPU8.set(new Uint8Array(h),u),p._loadModel(h.byteLength),i=p}return await f(),{tflite:i,isSIMDSupported:s}}var _e,ge;const ft=class{constructor(r,e){me(this,_e,void 0);me(this,ge,void 0);ae(this,_e,r),ae(this,ge,e)}static async init({meeting:r,segmentationConfig:e,postProcessingConfig:i}){this.isSupported()||console.error("Initialising it in an unsupported environment, the middleware might not work"),window.addEventListener("error",l=>{var m;!((m=l.filename)!=null&&m.includes("localhost"))&&l.lineno!==0&&console.error("RealtimeKitVideoBackgroundTransformer::UnhandledError",l.error)}),window.addEventListener("unhandledrejection",l=>{console.error("RealtimeKitVideoBackgroundTransformer::UnhandledRejection",l.reason)});const s={model:"mlkit",backend:"wasmSimd",inputResolution:"256x256",pipeline:"webgl2",targetFps:35,deferInputResizing:!0,...e||{}};it().getEngineName()==="WebKit"&&(s.pipeline="canvas2dCpu");const f={smoothSegmentationMask:!0,jointBilateralFilter:{sigmaSpace:1,sigmaColor:.1},coverage:[.5,.75],lightWrapping:.3,blendMode:"screen",...i||{}};await r.self.setVideoMiddlewareGlobalConfig({disablePerFrameCanvasRendering:!0});const{tflite:p}=await Nt(s);return new ft(await ot.init({meeting:r,segmentationConfig:s,postProcessingConfig:f,tflite:p}),await st.init({meeting:r,segmentationConfig:s,postProcessingConfig:f,tflite:p}))}static isSupported(){var e;let r=!1;try{const i=it(),s=document.createElement("canvas"),c=s.getContext("webgl2",{})||s.getContext("webgl",{}),f=+((e=i.getBrowserVersion())==null?void 0:e.split(".")[0]);if(!c||i.getOSName()==="iOS"||i.getBrowserName()==="Safari"&&f<17)return!1;r=!0}catch{r=!1}return r}async createStaticBackgroundVideoMiddleware(r){return await O(this,_e).createStaticBackgroundImageVideoMiddleware(r)}async createBackgroundBlurVideoMiddleware(r=50){return O(this,ge).createBackgroundBlurVideoMiddleware(r)}destruct(){O(this,_e).destruct(),O(this,ge).destruct()}};let at=ft;_e=new WeakMap,ge=new WeakMap;module.exports=at;
package/dist/index.es.js CHANGED
@@ -2738,7 +2738,7 @@ function buildCanvas2dPipeline(sourcePlayback, backgroundConfig, segmentationCon
2738
2738
  const outputMemoryOffset = tflite._getOutputMemoryOffset() / 4;
2739
2739
  let postProcessingConfig;
2740
2740
  let currentFrame = null;
2741
- const blurredBackgroundImagePromise = loadImage("https://assets.dyte.io/backgrounds/blur.jpg");
2741
+ const blurredBackgroundImagePromise = loadImage("https://rtk-assets.realtime.cloudflare.com/backgrounds/blur.jpg");
2742
2742
  async function render() {
2743
2743
  currentFrame = await createImageFromVideoElement(sourcePlayback.htmlElement);
2744
2744
  if (backgroundConfig.type !== "none") {
@@ -2972,7 +2972,7 @@ let SimpleBackgroundTransformer = _SimpleBackgroundTransformer;
2972
2972
  _initParams2 = new WeakMap();
2973
2973
  _activeRunId2 = new WeakMap();
2974
2974
  var createTFLiteModule = (() => {
2975
- var _scriptDir = "https://assets.dyte.io/virtual-bg/";
2975
+ var _scriptDir = "https://rtk-assets.realtime.cloudflare.com/virtual-bg/";
2976
2976
  return function(createTFLiteModule2) {
2977
2977
  createTFLiteModule2 = createTFLiteModule2 || {};
2978
2978
  var Module = typeof createTFLiteModule2 != "undefined" ? createTFLiteModule2 : {};
@@ -3549,7 +3549,7 @@ var createTFLiteModule = (() => {
3549
3549
  };
3550
3550
  })();
3551
3551
  var createTFLiteSIMDModule = (() => {
3552
- var _scriptDir = "https://assets.dyte.io/virtual-bg/";
3552
+ var _scriptDir = "https://rtk-assets.realtime.cloudflare.com/virtual-bg/";
3553
3553
  return function(createTFLiteSIMDModule2) {
3554
3554
  createTFLiteSIMDModule2 = createTFLiteSIMDModule2 || {};
3555
3555
  var Module = typeof createTFLiteSIMDModule2 != "undefined" ? createTFLiteSIMDModule2 : {};
@@ -4158,7 +4158,7 @@ async function useTFLite(segmentationConfig) {
4158
4158
  segmentationConfig.inputResolution
4159
4159
  );
4160
4160
  const modelResponse = await fetch(
4161
- `https://dyte-plugins.s3.ap-south-1.amazonaws.com/tf-assets/models/${modelFileName}.tflite`
4161
+ `https://rtk-assets.realtime.cloudflare.com/virtual-bg/tf-assets/models/${modelFileName}.tflite`
4162
4162
  );
4163
4163
  const model = await modelResponse.arrayBuffer();
4164
4164
  const modelBufferOffset = newSelectedTFLite._getModelBufferMemoryOffset();
@@ -228,4 +228,4 @@ var vt=(G,X,ee)=>{if(!X.has(G))throw TypeError("Cannot "+ee)};var O=(G,X,ee)=>(v
228
228
  * https://github.com/lancedikson/bowser
229
229
  * MIT License | (c) Dustin Diaz 2012-2015
230
230
  * MIT License | (c) Denis Demchenko 2015-2019
231
- */class Lt{static getParser(r,e=!1){if(typeof r!="string")throw new Error("UserAgent should be a string");return new _t(r,e)}static parse(r){return new _t(r).getResult()}static get BROWSER_MAP(){return ht}static get ENGINE_MAP(){return le}static get OS_MAP(){return z}static get PLATFORMS_MAP(){return D}}function Ce(){return Lt.getParser(window.navigator.userAgent)}function gt(t,r,e,i,s,c){const f=i.getContext("2d"),[p,l]=ue[e.inputResolution],m=p*l,h=new ImageData(p,l),u=document.createElement("canvas");u.width=p,u.height=l;const w=u.getContext("2d",{willReadFrequently:!0}),E=s._getInputMemoryOffset()/4,_=s._getOutputMemoryOffset()/4;let R,b=null;const T=X("https://assets.dyte.io/backgrounds/blur.jpg");async function U(){b=await ee(t.htmlElement),r.type!=="none"&&C(),r.type!=="none"&&B(),await x()}function W(A){R=A}function j(){}function C(){if(w.drawImage(b,0,0,t.width,t.height,0,0,p,l),e.model==="meet"||e.model==="mlkit"){const A=w.getImageData(0,0,p,l);for(let L=0;L<m;L++)s.HEAPF32[E+L*3]=A.data[L*4]/255,s.HEAPF32[E+L*3+1]=A.data[L*4+1]/255,s.HEAPF32[E+L*3+2]=A.data[L*4+2]/255}}function B(){s._runInference();for(let A=0;A<m;A++)if(e.model==="meet"){const L=s.HEAPF32[_+A*2],ae=s.HEAPF32[_+A*2+1],F=Math.max(L,ae),te=Math.exp(L-F),re=Math.exp(ae-F);h.data[A*4+3]=255*re/(te+re)}else if(e.model==="mlkit"){const L=s.HEAPF32[_+A];h.data[A*4+3]=255*L}w.putImageData(h,0,0)}async function x(){f.globalCompositeOperation="copy",f.filter="none",f.drawImage(b,0,0),R!=null&&R.smoothSegmentationMask&&(r.type==="blur"?f.filter="blur(8px)":r.type==="image"&&(f.filter="blur(4px)")),r.type!=="none"&&(f.globalCompositeOperation="destination-in",f.filter="none",H()),r.type==="blur"?await N():q()}function q(){f.globalCompositeOperation="destination-over",f.drawImage(r.backgroundImage,0,0)}function H(){f.drawImage(u,0,0,p,l,0,0,t.width,t.height)}async function N(){if(f.globalCompositeOperation="destination-over",Ce().getBrowserName()==="Safari"){const A=await T;f.drawImage(A,0,0)}else f.filter=`blur(${r.blurLength}px)`,f.drawImage(b,0,0)}return{render:U,updatePostProcessingConfig:W,cleanUp:j}}const Oe=class extends G{constructor(e){super();ge(this,Q,void 0);ge(this,ve,void 0);de(this,Q,e)}static async init(e){return new Oe(e)}async createStaticBackgroundImageVideoMiddleware(e){const i=await X(e);return async({canvas:s,WorkerTimers:c})=>{const f=`RUN_${Date.now()}_${Math.round(Math.random()*100)}`;de(this,ve,f);const p=await this.createCameraVideoElement(O(this,Q).meeting.self.rawVideoTrack);s.width=p.width,s.height=p.height;const m=(O(this,Q).segmentationConfig.pipeline==="canvas2dCpu"?gt:pt)({htmlElement:p,width:O(this,Q).meeting.self.rawVideoTrack.getSettings().width,height:O(this,Q).meeting.self.rawVideoTrack.getSettings().height},{type:"image",backgroundImage:i},O(this,Q).segmentationConfig,s,O(this,Q).tflite,c);m.updatePostProcessingConfig(O(this,Q).postProcessingConfig);const h=1e3/O(this,Q).segmentationConfig.targetFps,u=async()=>{if(f!==O(this,ve)||!O(this,Q).meeting.self.videoEnabled){await m.cleanUp();return}const w=performance.now();await m.render(),c.setTimeout(u,Math.max(0,h-(performance.now()-w)))};c.setTimeout(()=>{u()},0)}}destruct(){de(this,ve,null)}};let Be=Oe;Q=new WeakMap,ve=new WeakMap;const Ue=class extends G{constructor(e){super();ge(this,$,void 0);ge(this,be,void 0);de(this,$,e)}static async init(e){return new Ue(e)}async createBackgroundBlurVideoMiddleware(e){return async({canvas:i,WorkerTimers:s})=>{const c=`RUN_${Date.now()}_${Math.round(Math.random()*100)}`;de(this,be,c);const f=await this.createCameraVideoElement(O(this,$).meeting.self.rawVideoTrack);i.width=f.width,i.height=f.height;const l=(O(this,$).segmentationConfig.pipeline==="canvas2dCpu"?gt:pt)({htmlElement:f,width:O(this,$).meeting.self.rawVideoTrack.getSettings().width,height:O(this,$).meeting.self.rawVideoTrack.getSettings().height},{type:"blur",blurLength:e},O(this,$).segmentationConfig,i,O(this,$).tflite,s);l.updatePostProcessingConfig(O(this,$).postProcessingConfig);const m=1e3/O(this,$).segmentationConfig.targetFps,h=async()=>{if(c!==O(this,be)||!O(this,$).meeting.self.videoEnabled){await l.cleanUp();return}const u=performance.now();await l.render(),s.setTimeout(h,Math.max(0,m-(performance.now()-u)))};s.setTimeout(()=>{h()},0)}}async destruct(){de(this,be,null)}};let Pe=Ue;$=new WeakMap,be=new WeakMap;var Dt=(()=>{var t="https://assets.dyte.io/virtual-bg/";return function(r){r=r||{};var e=typeof r!="undefined"?r:{},i,s;e.ready=new Promise(function(n,o){i=n,s=o});var c=Object.assign({},e),f="./this.program",p=(n,o)=>{throw o},l=!0,m="";function h(n){return e.locateFile?e.locateFile(n,m):m+n}var u;typeof document!="undefined"&&document.currentScript&&(m=document.currentScript.src),m=t,m.indexOf("blob:")!==0?m=m.substr(0,m.replace(/[?#].*/,"").lastIndexOf("/")+1):m="";var w=e.print||console.log.bind(console),E=e.printErr||console.warn.bind(console);Object.assign(e,c),c=null,e.arguments&&e.arguments,e.thisProgram&&(f=e.thisProgram),e.quit&&(p=e.quit);var _;e.wasmBinary&&(_=e.wasmBinary);var R=e.noExitRuntime||!0;typeof WebAssembly!="object"&&Y("no native wasm support detected");var b,T=!1,U=typeof TextDecoder!="undefined"?new TextDecoder("utf8"):void 0;function W(n,o,d){for(var v=o+d,y=o;n[y]&&!(y>=v);)++y;if(y-o>16&&n.buffer&&U)return U.decode(n.subarray(o,y));for(var M="";o<y;){var g=n[o++];if(!(g&128)){M+=String.fromCharCode(g);continue}var S=n[o++]&63;if((g&224)==192){M+=String.fromCharCode((g&31)<<6|S);continue}var k=n[o++]&63;if((g&240)==224?g=(g&15)<<12|S<<6|k:g=(g&7)<<18|S<<12|k<<6|n[o++]&63,g<65536)M+=String.fromCharCode(g);else{var Z=g-65536;M+=String.fromCharCode(55296|Z>>10,56320|Z&1023)}}return M}var j,C,B,x;function q(n){j=n,e.HEAP8=C=new Int8Array(n),e.HEAP16=new Int16Array(n),e.HEAP32=new Int32Array(n),e.HEAPU8=B=new Uint8Array(n),e.HEAPU16=new Uint16Array(n),e.HEAPU32=x=new Uint32Array(n),e.HEAPF32=new Float32Array(n),e.HEAPF64=new Float64Array(n)}e.INITIAL_MEMORY;var H=[],N=[],A=[];function L(){return R}function ae(){if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)re(e.preRun.shift());he(H)}function F(){he(N)}function te(){if(e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;)ne(e.postRun.shift());he(A)}function re(n){H.unshift(n)}function J(n){N.unshift(n)}function ne(n){A.unshift(n)}var V=0,K=null;function Ee(n){V++,e.monitorRunDependencies&&e.monitorRunDependencies(V)}function Le(n){if(V--,e.monitorRunDependencies&&e.monitorRunDependencies(V),V==0&&K){var o=K;K=null,o()}}function Y(n){e.onAbort&&e.onAbort(n),n="Aborted("+n+")",E(n),T=!0,n+=". Build with -sASSERTIONS for more info.";var o=new WebAssembly.RuntimeError(n);throw s(o),o}var De="data:application/octet-stream;base64,";function Re(n){return n.startsWith(De)}var I;I="tflite.wasm",Re(I)||(I=h(I));function Me(n){try{if(n==I&&_)return new Uint8Array(_);throw"both async and sync fetching of the wasm failed"}catch(o){Y(o)}}function je(){return!_&&l&&typeof fetch=="function"?fetch(I,{credentials:"same-origin"}).then(function(n){if(!n.ok)throw"failed to load wasm binary file at '"+I+"'";return n.arrayBuffer()}).catch(function(){return Me(I)}):Promise.resolve().then(function(){return Me(I)})}function Ne(){var n={env:Te,wasi_snapshot_preview1:Te};function o(g,S){var k=g.exports;e.asm=k,b=e.asm.memory,q(b.buffer),e.asm.__indirect_function_table,J(e.asm.__wasm_call_ctors),Le()}Ee();function d(g){o(g.instance)}function v(g){return je().then(function(S){return WebAssembly.instantiate(S,n)}).then(function(S){return S}).then(g,function(S){E("failed to asynchronously prepare wasm: "+S),Y(S)})}function y(){return!_&&typeof WebAssembly.instantiateStreaming=="function"&&!Re(I)&&typeof fetch=="function"?fetch(I,{credentials:"same-origin"}).then(function(g){var S=WebAssembly.instantiateStreaming(g,n);return S.then(d,function(k){return E("wasm streaming compile failed: "+k),E("falling back to ArrayBuffer instantiation"),v(d)})}):v(d)}if(e.instantiateWasm)try{var M=e.instantiateWasm(n,o);return M}catch(g){E("Module.instantiateWasm callback failed with error: "+g),s(g)}return y().catch(s),{}}function We(n){this.name="ExitStatus",this.message="Program terminated with exit("+n+")",this.status=n}function he(n){for(;n.length>0;)n.shift()(e)}function He(n){}var Se="To use dlopen, you need enable dynamic linking, see https://github.com/emscripten-core/emscripten/wiki/Linking";function Ve(n,o){Y(Se)}function Ge(n,o){Y(Se)}var Xe=!0;function ze(){return Xe}function qe(n,o,d,v,y,M){return-52}function Ke(n,o,d,v,y,M){}function Ye(){Y("")}function Qe(){return Date.now()}function Ae(){return 2147483648}function $e(){return Ae()}var Fe;Fe=()=>performance.now();function Je(n,o,d){B.copyWithin(n,o,o+d)}function Ze(n){try{return b.grow(n-j.byteLength+65535>>>16),q(b.buffer),1}catch{}}function et(n){var o=B.length;n=n>>>0;var d=Ae();if(n>d)return!1;let v=(k,Z)=>k+(Z-k%Z)%Z;for(var y=1;y<=4;y*=2){var M=o*(1+.2/y);M=Math.min(M,n+100663296);var g=Math.min(d,v(Math.max(n,M),65536)),S=Ze(g);if(S)return!0}return!1}var _e={};function tt(){return f||"./this.program"}function ie(){if(!ie.strings){var n=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",o={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:n,_:tt()};for(var d in _e)_e[d]===void 0?delete o[d]:o[d]=_e[d];var v=[];for(var d in o)v.push(d+"="+o[d]);ie.strings=v}return ie.strings}function rt(n,o,d){for(var v=0;v<n.length;++v)C[o++>>0]=n.charCodeAt(v);d||(C[o>>0]=0)}function nt(n,o){var d=0;return ie().forEach(function(v,y){var M=o+d;x[n+y*4>>2]=M,rt(v,M),d+=v.length+1}),0}function it(n,o){var d=ie();x[n>>2]=d.length;var v=0;return d.forEach(function(y){v+=y.length+1}),x[o>>2]=v,0}function ot(n){L()||(e.onExit&&e.onExit(n),T=!0),p(n,new We(n))}function st(n,o){ot(n)}var at=st;function ut(n){return 52}function ct(n,o,d,v,y){return 70}var ft=[null,[],[]];function dt(n,o){var d=ft[n];o===0||o===10?((n===1?w:E)(W(d,0)),d.length=0):d.push(o)}function mt(n,o,d,v){for(var y=0,M=0;M<d;M++){var g=x[o>>2],S=x[o+4>>2];o+=8;for(var k=0;k<S;k++)dt(n,B[g+k]);y+=S}return x[v>>2]=y,0}function lt(){if(typeof crypto=="object"&&typeof crypto.getRandomValues=="function"){var n=new Uint8Array(1);return()=>(crypto.getRandomValues(n),n[0])}else return()=>Y("randomDevice")}function ce(n,o){ce.randomDevice||(ce.randomDevice=lt());for(var d=0;d<o;d++)C[n+d>>0]=ce.randomDevice();return 0}var Te={_dlinit:He,_dlopen_js:Ve,_dlsym_js:Ge,_emscripten_get_now_is_monotonic:ze,_mmap_js:qe,_munmap_js:Ke,abort:Ye,emscripten_date_now:Qe,emscripten_get_heap_max:$e,emscripten_get_now:Fe,emscripten_memcpy_big:Je,emscripten_resize_heap:et,environ_get:nt,environ_sizes_get:it,exit:at,fd_close:ut,fd_seek:ct,fd_write:mt,getentropy:ce};Ne(),e.___wasm_call_ctors=function(){return(e.___wasm_call_ctors=e.asm.__wasm_call_ctors).apply(null,arguments)},e._getModelBufferMemoryOffset=function(){return(e._getModelBufferMemoryOffset=e.asm.getModelBufferMemoryOffset).apply(null,arguments)},e._getInputMemoryOffset=function(){return(e._getInputMemoryOffset=e.asm.getInputMemoryOffset).apply(null,arguments)},e._getInputHeight=function(){return(e._getInputHeight=e.asm.getInputHeight).apply(null,arguments)},e._getInputWidth=function(){return(e._getInputWidth=e.asm.getInputWidth).apply(null,arguments)},e._getInputChannelCount=function(){return(e._getInputChannelCount=e.asm.getInputChannelCount).apply(null,arguments)},e._getOutputMemoryOffset=function(){return(e._getOutputMemoryOffset=e.asm.getOutputMemoryOffset).apply(null,arguments)},e._getOutputHeight=function(){return(e._getOutputHeight=e.asm.getOutputHeight).apply(null,arguments)},e._getOutputWidth=function(){return(e._getOutputWidth=e.asm.getOutputWidth).apply(null,arguments)},e._getOutputChannelCount=function(){return(e._getOutputChannelCount=e.asm.getOutputChannelCount).apply(null,arguments)},e._loadModel=function(){return(e._loadModel=e.asm.loadModel).apply(null,arguments)},e._runInference=function(){return(e._runInference=e.asm.runInference).apply(null,arguments)},e._malloc=function(){return(e._malloc=e.asm.malloc).apply(null,arguments)},e.___errno_location=function(){return(e.___errno_location=e.asm.__errno_location).apply(null,arguments)},e.___dl_seterr=function(){return(e.___dl_seterr=e.asm.__dl_seterr).apply(null,arguments)},e.stackSave=function(){return(e.stackSave=e.asm.stackSave).apply(null,arguments)},e.stackRestore=function(){return(e.stackRestore=e.asm.stackRestore).apply(null,arguments)},e.stackAlloc=function(){return(e.stackAlloc=e.asm.stackAlloc).apply(null,arguments)},e.dynCall_jjj=function(){return(e.dynCall_jjj=e.asm.dynCall_jjj).apply(null,arguments)},e.dynCall_jiii=function(){return(e.dynCall_jiii=e.asm.dynCall_jiii).apply(null,arguments)},e.dynCall_iiiijj=function(){return(e.dynCall_iiiijj=e.asm.dynCall_iiiijj).apply(null,arguments)},e.dynCall_viijj=function(){return(e.dynCall_viijj=e.asm.dynCall_viijj).apply(null,arguments)},e.dynCall_viiijjj=function(){return(e.dynCall_viiijjj=e.asm.dynCall_viiijjj).apply(null,arguments)},e.dynCall_iijjiiii=function(){return(e.dynCall_iijjiiii=e.asm.dynCall_iijjiiii).apply(null,arguments)},e.dynCall_jiji=function(){return(e.dynCall_jiji=e.asm.dynCall_jiji).apply(null,arguments)};var fe;K=function n(){fe||xe(),fe||(K=n)};function xe(n){if(V>0||(ae(),V>0))return;function o(){fe||(fe=!0,e.calledRun=!0,!T&&(F(),i(e),e.onRuntimeInitialized&&e.onRuntimeInitialized(),te()))}e.setStatus?(e.setStatus("Running..."),setTimeout(function(){setTimeout(function(){e.setStatus("")},1),o()},1)):o()}if(e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);e.preInit.length>0;)e.preInit.pop()();return xe(),r.ready}})(),jt=(()=>{var t="https://assets.dyte.io/virtual-bg/";return function(r){r=r||{};var e=typeof r!="undefined"?r:{},i,s;e.ready=new Promise(function(n,o){i=n,s=o});var c=Object.assign({},e),f="./this.program",p=(n,o)=>{throw o},l=!0,m="";function h(n){return e.locateFile?e.locateFile(n,m):m+n}var u;typeof document!="undefined"&&document.currentScript&&(m=document.currentScript.src),m=t,m.indexOf("blob:")!==0?m=m.substr(0,m.replace(/[?#].*/,"").lastIndexOf("/")+1):m="";var w=e.print||console.log.bind(console),E=e.printErr||console.warn.bind(console);Object.assign(e,c),c=null,e.arguments&&e.arguments,e.thisProgram&&(f=e.thisProgram),e.quit&&(p=e.quit);var _;e.wasmBinary&&(_=e.wasmBinary);var R=e.noExitRuntime||!0;typeof WebAssembly!="object"&&Y("no native wasm support detected");var b,T=!1,U=typeof TextDecoder!="undefined"?new TextDecoder("utf8"):void 0;function W(n,o,d){for(var v=o+d,y=o;n[y]&&!(y>=v);)++y;if(y-o>16&&n.buffer&&U)return U.decode(n.subarray(o,y));for(var M="";o<y;){var g=n[o++];if(!(g&128)){M+=String.fromCharCode(g);continue}var S=n[o++]&63;if((g&224)==192){M+=String.fromCharCode((g&31)<<6|S);continue}var k=n[o++]&63;if((g&240)==224?g=(g&15)<<12|S<<6|k:g=(g&7)<<18|S<<12|k<<6|n[o++]&63,g<65536)M+=String.fromCharCode(g);else{var Z=g-65536;M+=String.fromCharCode(55296|Z>>10,56320|Z&1023)}}return M}var j,C,B,x;function q(n){j=n,e.HEAP8=C=new Int8Array(n),e.HEAP16=new Int16Array(n),e.HEAP32=new Int32Array(n),e.HEAPU8=B=new Uint8Array(n),e.HEAPU16=new Uint16Array(n),e.HEAPU32=x=new Uint32Array(n),e.HEAPF32=new Float32Array(n),e.HEAPF64=new Float64Array(n)}e.INITIAL_MEMORY;var H=[],N=[],A=[];function L(){return R}function ae(){if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)re(e.preRun.shift());he(H)}function F(){he(N)}function te(){if(e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;)ne(e.postRun.shift());he(A)}function re(n){H.unshift(n)}function J(n){N.unshift(n)}function ne(n){A.unshift(n)}var V=0,K=null;function Ee(n){V++,e.monitorRunDependencies&&e.monitorRunDependencies(V)}function Le(n){if(V--,e.monitorRunDependencies&&e.monitorRunDependencies(V),V==0&&K){var o=K;K=null,o()}}function Y(n){e.onAbort&&e.onAbort(n),n="Aborted("+n+")",E(n),T=!0,n+=". Build with -sASSERTIONS for more info.";var o=new WebAssembly.RuntimeError(n);throw s(o),o}var De="data:application/octet-stream;base64,";function Re(n){return n.startsWith(De)}var I;I="tflite-simd.wasm",Re(I)||(I=h(I));function Me(n){try{if(n==I&&_)return new Uint8Array(_);throw"both async and sync fetching of the wasm failed"}catch(o){Y(o)}}function je(){return!_&&l&&typeof fetch=="function"?fetch(I,{credentials:"same-origin"}).then(function(n){if(!n.ok)throw"failed to load wasm binary file at '"+I+"'";return n.arrayBuffer()}).catch(function(){return Me(I)}):Promise.resolve().then(function(){return Me(I)})}function Ne(){var n={env:Te,wasi_snapshot_preview1:Te};function o(g,S){var k=g.exports;e.asm=k,b=e.asm.memory,q(b.buffer),e.asm.__indirect_function_table,J(e.asm.__wasm_call_ctors),Le()}Ee();function d(g){o(g.instance)}function v(g){return je().then(function(S){return WebAssembly.instantiate(S,n)}).then(function(S){return S}).then(g,function(S){E("failed to asynchronously prepare wasm: "+S),Y(S)})}function y(){return!_&&typeof WebAssembly.instantiateStreaming=="function"&&!Re(I)&&typeof fetch=="function"?fetch(I,{credentials:"same-origin"}).then(function(g){var S=WebAssembly.instantiateStreaming(g,n);return S.then(d,function(k){return E("wasm streaming compile failed: "+k),E("falling back to ArrayBuffer instantiation"),v(d)})}):v(d)}if(e.instantiateWasm)try{var M=e.instantiateWasm(n,o);return M}catch(g){E("Module.instantiateWasm callback failed with error: "+g),s(g)}return y().catch(s),{}}function We(n){this.name="ExitStatus",this.message="Program terminated with exit("+n+")",this.status=n}function he(n){for(;n.length>0;)n.shift()(e)}function He(n){}var Se="To use dlopen, you need enable dynamic linking, see https://github.com/emscripten-core/emscripten/wiki/Linking";function Ve(n,o){Y(Se)}function Ge(n,o){Y(Se)}var Xe=!0;function ze(){return Xe}function qe(n,o,d,v,y,M){return-52}function Ke(n,o,d,v,y,M){}function Ye(){Y("")}function Qe(){return Date.now()}function Ae(){return 2147483648}function $e(){return Ae()}var Fe;Fe=()=>performance.now();function Je(n,o,d){B.copyWithin(n,o,o+d)}function Ze(n){try{return b.grow(n-j.byteLength+65535>>>16),q(b.buffer),1}catch{}}function et(n){var o=B.length;n=n>>>0;var d=Ae();if(n>d)return!1;let v=(k,Z)=>k+(Z-k%Z)%Z;for(var y=1;y<=4;y*=2){var M=o*(1+.2/y);M=Math.min(M,n+100663296);var g=Math.min(d,v(Math.max(n,M),65536)),S=Ze(g);if(S)return!0}return!1}var _e={};function tt(){return f||"./this.program"}function ie(){if(!ie.strings){var n=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",o={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:n,_:tt()};for(var d in _e)_e[d]===void 0?delete o[d]:o[d]=_e[d];var v=[];for(var d in o)v.push(d+"="+o[d]);ie.strings=v}return ie.strings}function rt(n,o,d){for(var v=0;v<n.length;++v)C[o++>>0]=n.charCodeAt(v);d||(C[o>>0]=0)}function nt(n,o){var d=0;return ie().forEach(function(v,y){var M=o+d;x[n+y*4>>2]=M,rt(v,M),d+=v.length+1}),0}function it(n,o){var d=ie();x[n>>2]=d.length;var v=0;return d.forEach(function(y){v+=y.length+1}),x[o>>2]=v,0}function ot(n){L()||(e.onExit&&e.onExit(n),T=!0),p(n,new We(n))}function st(n,o){ot(n)}var at=st;function ut(n){return 52}function ct(n,o,d,v,y){return 70}var ft=[null,[],[]];function dt(n,o){var d=ft[n];o===0||o===10?((n===1?w:E)(W(d,0)),d.length=0):d.push(o)}function mt(n,o,d,v){for(var y=0,M=0;M<d;M++){var g=x[o>>2],S=x[o+4>>2];o+=8;for(var k=0;k<S;k++)dt(n,B[g+k]);y+=S}return x[v>>2]=y,0}function lt(){if(typeof crypto=="object"&&typeof crypto.getRandomValues=="function"){var n=new Uint8Array(1);return()=>(crypto.getRandomValues(n),n[0])}else return()=>Y("randomDevice")}function ce(n,o){ce.randomDevice||(ce.randomDevice=lt());for(var d=0;d<o;d++)C[n+d>>0]=ce.randomDevice();return 0}var Te={_dlinit:He,_dlopen_js:Ve,_dlsym_js:Ge,_emscripten_get_now_is_monotonic:ze,_mmap_js:qe,_munmap_js:Ke,abort:Ye,emscripten_date_now:Qe,emscripten_get_heap_max:$e,emscripten_get_now:Fe,emscripten_memcpy_big:Je,emscripten_resize_heap:et,environ_get:nt,environ_sizes_get:it,exit:at,fd_close:ut,fd_seek:ct,fd_write:mt,getentropy:ce};Ne(),e.___wasm_call_ctors=function(){return(e.___wasm_call_ctors=e.asm.__wasm_call_ctors).apply(null,arguments)},e._getModelBufferMemoryOffset=function(){return(e._getModelBufferMemoryOffset=e.asm.getModelBufferMemoryOffset).apply(null,arguments)},e._getInputMemoryOffset=function(){return(e._getInputMemoryOffset=e.asm.getInputMemoryOffset).apply(null,arguments)},e._getInputHeight=function(){return(e._getInputHeight=e.asm.getInputHeight).apply(null,arguments)},e._getInputWidth=function(){return(e._getInputWidth=e.asm.getInputWidth).apply(null,arguments)},e._getInputChannelCount=function(){return(e._getInputChannelCount=e.asm.getInputChannelCount).apply(null,arguments)},e._getOutputMemoryOffset=function(){return(e._getOutputMemoryOffset=e.asm.getOutputMemoryOffset).apply(null,arguments)},e._getOutputHeight=function(){return(e._getOutputHeight=e.asm.getOutputHeight).apply(null,arguments)},e._getOutputWidth=function(){return(e._getOutputWidth=e.asm.getOutputWidth).apply(null,arguments)},e._getOutputChannelCount=function(){return(e._getOutputChannelCount=e.asm.getOutputChannelCount).apply(null,arguments)},e._loadModel=function(){return(e._loadModel=e.asm.loadModel).apply(null,arguments)},e._runInference=function(){return(e._runInference=e.asm.runInference).apply(null,arguments)},e._malloc=function(){return(e._malloc=e.asm.malloc).apply(null,arguments)},e.___errno_location=function(){return(e.___errno_location=e.asm.__errno_location).apply(null,arguments)},e.___dl_seterr=function(){return(e.___dl_seterr=e.asm.__dl_seterr).apply(null,arguments)},e.stackSave=function(){return(e.stackSave=e.asm.stackSave).apply(null,arguments)},e.stackRestore=function(){return(e.stackRestore=e.asm.stackRestore).apply(null,arguments)},e.stackAlloc=function(){return(e.stackAlloc=e.asm.stackAlloc).apply(null,arguments)},e.dynCall_jjj=function(){return(e.dynCall_jjj=e.asm.dynCall_jjj).apply(null,arguments)},e.dynCall_jiii=function(){return(e.dynCall_jiii=e.asm.dynCall_jiii).apply(null,arguments)},e.dynCall_iiiijj=function(){return(e.dynCall_iiiijj=e.asm.dynCall_iiiijj).apply(null,arguments)},e.dynCall_viijj=function(){return(e.dynCall_viijj=e.asm.dynCall_viijj).apply(null,arguments)},e.dynCall_viiijjj=function(){return(e.dynCall_viiijjj=e.asm.dynCall_viiijjj).apply(null,arguments)},e.dynCall_iijjiiii=function(){return(e.dynCall_iijjiiii=e.asm.dynCall_iijjiiii).apply(null,arguments)},e.dynCall_jiji=function(){return(e.dynCall_jiji=e.asm.dynCall_jiji).apply(null,arguments)};var fe;K=function n(){fe||xe(),fe||(K=n)};function xe(n){if(V>0||(ae(),V>0))return;function o(){fe||(fe=!0,e.calledRun=!0,!T&&(F(),i(e),e.onRuntimeInitialized&&e.onRuntimeInitialized(),te()))}e.setStatus?(e.setStatus("Running..."),setTimeout(function(){setTimeout(function(){e.setStatus("")},1),o()},1)):o()}if(e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);e.preInit.length>0;)e.preInit.pop()();return xe(),r.ready}})();async function Nt(t){let r=null,e=null,i=null,s=!1;async function c(){r=await Dt();try{e=await jt(),s=!0,t.backend="wasmSimd"}catch(p){console.warn("Failed to create TFLite SIMD WebAssembly module.",p)}}await c();async function f(){if(!r||s&&!e||!s&&t.backend==="wasmSimd"||t.model!=="meet"&&t.model!=="mlkit")return;i=null;const p=t.backend==="wasmSimd"?e:r;if(!p)throw new Error(`TFLite backend unavailable: ${t.backend}`);const l=bt(t.model,t.inputResolution),h=await(await fetch(`https://dyte-plugins.s3.ap-south-1.amazonaws.com/tf-assets/models/${l}.tflite`)).arrayBuffer(),u=p._getModelBufferMemoryOffset();p.HEAPU8.set(new Uint8Array(h),u),p._loadModel(h.byteLength),i=p}return await f(),{tflite:i,isSIMDSupported:s}}const Ie=class{constructor(r,e){ge(this,we,void 0);ge(this,ye,void 0);de(this,we,r),de(this,ye,e)}static async init({meeting:r,segmentationConfig:e,postProcessingConfig:i}){this.isSupported()||console.error("Initialising it in an unsupported environment, the middleware might not work"),window.addEventListener("error",l=>{var m;!((m=l.filename)!=null&&m.includes("localhost"))&&l.lineno!==0&&console.error("RealtimeKitVideoBackgroundTransformer::UnhandledError",l.error)}),window.addEventListener("unhandledrejection",l=>{console.error("RealtimeKitVideoBackgroundTransformer::UnhandledRejection",l.reason)});const s={model:"mlkit",backend:"wasmSimd",inputResolution:"256x256",pipeline:"webgl2",targetFps:35,deferInputResizing:!0,...e||{}};Ce().getEngineName()==="WebKit"&&(s.pipeline="canvas2dCpu");const f={smoothSegmentationMask:!0,jointBilateralFilter:{sigmaSpace:1,sigmaColor:.1},coverage:[.5,.75],lightWrapping:.3,blendMode:"screen",...i||{}};await r.self.setVideoMiddlewareGlobalConfig({disablePerFrameCanvasRendering:!0});const{tflite:p}=await Nt(s);return new Ie(await Be.init({meeting:r,segmentationConfig:s,postProcessingConfig:f,tflite:p}),await Pe.init({meeting:r,segmentationConfig:s,postProcessingConfig:f,tflite:p}))}static isSupported(){var e;let r=!1;try{const i=Ce(),s=document.createElement("canvas"),c=s.getContext("webgl2",{})||s.getContext("webgl",{}),f=+((e=i.getBrowserVersion())==null?void 0:e.split(".")[0]);if(!c||i.getOSName()==="iOS"||i.getBrowserName()==="Safari"&&f<17)return!1;r=!0}catch{r=!1}return r}async createStaticBackgroundVideoMiddleware(r){return await O(this,we).createStaticBackgroundImageVideoMiddleware(r)}async createBackgroundBlurVideoMiddleware(r=50){return O(this,ye).createBackgroundBlurVideoMiddleware(r)}destruct(){O(this,we).destruct(),O(this,ye).destruct()}};let ke=Ie;return we=new WeakMap,ye=new WeakMap,ke}();
231
+ */class Lt{static getParser(r,e=!1){if(typeof r!="string")throw new Error("UserAgent should be a string");return new _t(r,e)}static parse(r){return new _t(r).getResult()}static get BROWSER_MAP(){return ht}static get ENGINE_MAP(){return le}static get OS_MAP(){return z}static get PLATFORMS_MAP(){return D}}function Ce(){return Lt.getParser(window.navigator.userAgent)}function gt(t,r,e,i,s,c){const f=i.getContext("2d"),[p,l]=ue[e.inputResolution],m=p*l,h=new ImageData(p,l),u=document.createElement("canvas");u.width=p,u.height=l;const w=u.getContext("2d",{willReadFrequently:!0}),E=s._getInputMemoryOffset()/4,_=s._getOutputMemoryOffset()/4;let R,b=null;const T=X("https://rtk-assets.realtime.cloudflare.com/backgrounds/blur.jpg");async function U(){b=await ee(t.htmlElement),r.type!=="none"&&C(),r.type!=="none"&&B(),await x()}function W(A){R=A}function j(){}function C(){if(w.drawImage(b,0,0,t.width,t.height,0,0,p,l),e.model==="meet"||e.model==="mlkit"){const A=w.getImageData(0,0,p,l);for(let L=0;L<m;L++)s.HEAPF32[E+L*3]=A.data[L*4]/255,s.HEAPF32[E+L*3+1]=A.data[L*4+1]/255,s.HEAPF32[E+L*3+2]=A.data[L*4+2]/255}}function B(){s._runInference();for(let A=0;A<m;A++)if(e.model==="meet"){const L=s.HEAPF32[_+A*2],ae=s.HEAPF32[_+A*2+1],F=Math.max(L,ae),te=Math.exp(L-F),re=Math.exp(ae-F);h.data[A*4+3]=255*re/(te+re)}else if(e.model==="mlkit"){const L=s.HEAPF32[_+A];h.data[A*4+3]=255*L}w.putImageData(h,0,0)}async function x(){f.globalCompositeOperation="copy",f.filter="none",f.drawImage(b,0,0),R!=null&&R.smoothSegmentationMask&&(r.type==="blur"?f.filter="blur(8px)":r.type==="image"&&(f.filter="blur(4px)")),r.type!=="none"&&(f.globalCompositeOperation="destination-in",f.filter="none",H()),r.type==="blur"?await N():q()}function q(){f.globalCompositeOperation="destination-over",f.drawImage(r.backgroundImage,0,0)}function H(){f.drawImage(u,0,0,p,l,0,0,t.width,t.height)}async function N(){if(f.globalCompositeOperation="destination-over",Ce().getBrowserName()==="Safari"){const A=await T;f.drawImage(A,0,0)}else f.filter=`blur(${r.blurLength}px)`,f.drawImage(b,0,0)}return{render:U,updatePostProcessingConfig:W,cleanUp:j}}const Oe=class extends G{constructor(e){super();ge(this,Q,void 0);ge(this,ve,void 0);de(this,Q,e)}static async init(e){return new Oe(e)}async createStaticBackgroundImageVideoMiddleware(e){const i=await X(e);return async({canvas:s,WorkerTimers:c})=>{const f=`RUN_${Date.now()}_${Math.round(Math.random()*100)}`;de(this,ve,f);const p=await this.createCameraVideoElement(O(this,Q).meeting.self.rawVideoTrack);s.width=p.width,s.height=p.height;const m=(O(this,Q).segmentationConfig.pipeline==="canvas2dCpu"?gt:pt)({htmlElement:p,width:O(this,Q).meeting.self.rawVideoTrack.getSettings().width,height:O(this,Q).meeting.self.rawVideoTrack.getSettings().height},{type:"image",backgroundImage:i},O(this,Q).segmentationConfig,s,O(this,Q).tflite,c);m.updatePostProcessingConfig(O(this,Q).postProcessingConfig);const h=1e3/O(this,Q).segmentationConfig.targetFps,u=async()=>{if(f!==O(this,ve)||!O(this,Q).meeting.self.videoEnabled){await m.cleanUp();return}const w=performance.now();await m.render(),c.setTimeout(u,Math.max(0,h-(performance.now()-w)))};c.setTimeout(()=>{u()},0)}}destruct(){de(this,ve,null)}};let Be=Oe;Q=new WeakMap,ve=new WeakMap;const Ue=class extends G{constructor(e){super();ge(this,$,void 0);ge(this,be,void 0);de(this,$,e)}static async init(e){return new Ue(e)}async createBackgroundBlurVideoMiddleware(e){return async({canvas:i,WorkerTimers:s})=>{const c=`RUN_${Date.now()}_${Math.round(Math.random()*100)}`;de(this,be,c);const f=await this.createCameraVideoElement(O(this,$).meeting.self.rawVideoTrack);i.width=f.width,i.height=f.height;const l=(O(this,$).segmentationConfig.pipeline==="canvas2dCpu"?gt:pt)({htmlElement:f,width:O(this,$).meeting.self.rawVideoTrack.getSettings().width,height:O(this,$).meeting.self.rawVideoTrack.getSettings().height},{type:"blur",blurLength:e},O(this,$).segmentationConfig,i,O(this,$).tflite,s);l.updatePostProcessingConfig(O(this,$).postProcessingConfig);const m=1e3/O(this,$).segmentationConfig.targetFps,h=async()=>{if(c!==O(this,be)||!O(this,$).meeting.self.videoEnabled){await l.cleanUp();return}const u=performance.now();await l.render(),s.setTimeout(h,Math.max(0,m-(performance.now()-u)))};s.setTimeout(()=>{h()},0)}}async destruct(){de(this,be,null)}};let Pe=Ue;$=new WeakMap,be=new WeakMap;var Dt=(()=>{var t="https://rtk-assets.realtime.cloudflare.com/virtual-bg/";return function(r){r=r||{};var e=typeof r!="undefined"?r:{},i,s;e.ready=new Promise(function(n,o){i=n,s=o});var c=Object.assign({},e),f="./this.program",p=(n,o)=>{throw o},l=!0,m="";function h(n){return e.locateFile?e.locateFile(n,m):m+n}var u;typeof document!="undefined"&&document.currentScript&&(m=document.currentScript.src),m=t,m.indexOf("blob:")!==0?m=m.substr(0,m.replace(/[?#].*/,"").lastIndexOf("/")+1):m="";var w=e.print||console.log.bind(console),E=e.printErr||console.warn.bind(console);Object.assign(e,c),c=null,e.arguments&&e.arguments,e.thisProgram&&(f=e.thisProgram),e.quit&&(p=e.quit);var _;e.wasmBinary&&(_=e.wasmBinary);var R=e.noExitRuntime||!0;typeof WebAssembly!="object"&&Y("no native wasm support detected");var b,T=!1,U=typeof TextDecoder!="undefined"?new TextDecoder("utf8"):void 0;function W(n,o,d){for(var v=o+d,y=o;n[y]&&!(y>=v);)++y;if(y-o>16&&n.buffer&&U)return U.decode(n.subarray(o,y));for(var M="";o<y;){var g=n[o++];if(!(g&128)){M+=String.fromCharCode(g);continue}var S=n[o++]&63;if((g&224)==192){M+=String.fromCharCode((g&31)<<6|S);continue}var k=n[o++]&63;if((g&240)==224?g=(g&15)<<12|S<<6|k:g=(g&7)<<18|S<<12|k<<6|n[o++]&63,g<65536)M+=String.fromCharCode(g);else{var Z=g-65536;M+=String.fromCharCode(55296|Z>>10,56320|Z&1023)}}return M}var j,C,B,x;function q(n){j=n,e.HEAP8=C=new Int8Array(n),e.HEAP16=new Int16Array(n),e.HEAP32=new Int32Array(n),e.HEAPU8=B=new Uint8Array(n),e.HEAPU16=new Uint16Array(n),e.HEAPU32=x=new Uint32Array(n),e.HEAPF32=new Float32Array(n),e.HEAPF64=new Float64Array(n)}e.INITIAL_MEMORY;var H=[],N=[],A=[];function L(){return R}function ae(){if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)re(e.preRun.shift());he(H)}function F(){he(N)}function te(){if(e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;)ne(e.postRun.shift());he(A)}function re(n){H.unshift(n)}function J(n){N.unshift(n)}function ne(n){A.unshift(n)}var V=0,K=null;function Ee(n){V++,e.monitorRunDependencies&&e.monitorRunDependencies(V)}function Le(n){if(V--,e.monitorRunDependencies&&e.monitorRunDependencies(V),V==0&&K){var o=K;K=null,o()}}function Y(n){e.onAbort&&e.onAbort(n),n="Aborted("+n+")",E(n),T=!0,n+=". Build with -sASSERTIONS for more info.";var o=new WebAssembly.RuntimeError(n);throw s(o),o}var De="data:application/octet-stream;base64,";function Re(n){return n.startsWith(De)}var I;I="tflite.wasm",Re(I)||(I=h(I));function Me(n){try{if(n==I&&_)return new Uint8Array(_);throw"both async and sync fetching of the wasm failed"}catch(o){Y(o)}}function je(){return!_&&l&&typeof fetch=="function"?fetch(I,{credentials:"same-origin"}).then(function(n){if(!n.ok)throw"failed to load wasm binary file at '"+I+"'";return n.arrayBuffer()}).catch(function(){return Me(I)}):Promise.resolve().then(function(){return Me(I)})}function Ne(){var n={env:Te,wasi_snapshot_preview1:Te};function o(g,S){var k=g.exports;e.asm=k,b=e.asm.memory,q(b.buffer),e.asm.__indirect_function_table,J(e.asm.__wasm_call_ctors),Le()}Ee();function d(g){o(g.instance)}function v(g){return je().then(function(S){return WebAssembly.instantiate(S,n)}).then(function(S){return S}).then(g,function(S){E("failed to asynchronously prepare wasm: "+S),Y(S)})}function y(){return!_&&typeof WebAssembly.instantiateStreaming=="function"&&!Re(I)&&typeof fetch=="function"?fetch(I,{credentials:"same-origin"}).then(function(g){var S=WebAssembly.instantiateStreaming(g,n);return S.then(d,function(k){return E("wasm streaming compile failed: "+k),E("falling back to ArrayBuffer instantiation"),v(d)})}):v(d)}if(e.instantiateWasm)try{var M=e.instantiateWasm(n,o);return M}catch(g){E("Module.instantiateWasm callback failed with error: "+g),s(g)}return y().catch(s),{}}function We(n){this.name="ExitStatus",this.message="Program terminated with exit("+n+")",this.status=n}function he(n){for(;n.length>0;)n.shift()(e)}function He(n){}var Se="To use dlopen, you need enable dynamic linking, see https://github.com/emscripten-core/emscripten/wiki/Linking";function Ve(n,o){Y(Se)}function Ge(n,o){Y(Se)}var Xe=!0;function ze(){return Xe}function qe(n,o,d,v,y,M){return-52}function Ke(n,o,d,v,y,M){}function Ye(){Y("")}function Qe(){return Date.now()}function Ae(){return 2147483648}function $e(){return Ae()}var Fe;Fe=()=>performance.now();function Je(n,o,d){B.copyWithin(n,o,o+d)}function Ze(n){try{return b.grow(n-j.byteLength+65535>>>16),q(b.buffer),1}catch{}}function et(n){var o=B.length;n=n>>>0;var d=Ae();if(n>d)return!1;let v=(k,Z)=>k+(Z-k%Z)%Z;for(var y=1;y<=4;y*=2){var M=o*(1+.2/y);M=Math.min(M,n+100663296);var g=Math.min(d,v(Math.max(n,M),65536)),S=Ze(g);if(S)return!0}return!1}var _e={};function tt(){return f||"./this.program"}function ie(){if(!ie.strings){var n=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",o={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:n,_:tt()};for(var d in _e)_e[d]===void 0?delete o[d]:o[d]=_e[d];var v=[];for(var d in o)v.push(d+"="+o[d]);ie.strings=v}return ie.strings}function rt(n,o,d){for(var v=0;v<n.length;++v)C[o++>>0]=n.charCodeAt(v);d||(C[o>>0]=0)}function nt(n,o){var d=0;return ie().forEach(function(v,y){var M=o+d;x[n+y*4>>2]=M,rt(v,M),d+=v.length+1}),0}function it(n,o){var d=ie();x[n>>2]=d.length;var v=0;return d.forEach(function(y){v+=y.length+1}),x[o>>2]=v,0}function ot(n){L()||(e.onExit&&e.onExit(n),T=!0),p(n,new We(n))}function st(n,o){ot(n)}var at=st;function ut(n){return 52}function ct(n,o,d,v,y){return 70}var ft=[null,[],[]];function dt(n,o){var d=ft[n];o===0||o===10?((n===1?w:E)(W(d,0)),d.length=0):d.push(o)}function mt(n,o,d,v){for(var y=0,M=0;M<d;M++){var g=x[o>>2],S=x[o+4>>2];o+=8;for(var k=0;k<S;k++)dt(n,B[g+k]);y+=S}return x[v>>2]=y,0}function lt(){if(typeof crypto=="object"&&typeof crypto.getRandomValues=="function"){var n=new Uint8Array(1);return()=>(crypto.getRandomValues(n),n[0])}else return()=>Y("randomDevice")}function ce(n,o){ce.randomDevice||(ce.randomDevice=lt());for(var d=0;d<o;d++)C[n+d>>0]=ce.randomDevice();return 0}var Te={_dlinit:He,_dlopen_js:Ve,_dlsym_js:Ge,_emscripten_get_now_is_monotonic:ze,_mmap_js:qe,_munmap_js:Ke,abort:Ye,emscripten_date_now:Qe,emscripten_get_heap_max:$e,emscripten_get_now:Fe,emscripten_memcpy_big:Je,emscripten_resize_heap:et,environ_get:nt,environ_sizes_get:it,exit:at,fd_close:ut,fd_seek:ct,fd_write:mt,getentropy:ce};Ne(),e.___wasm_call_ctors=function(){return(e.___wasm_call_ctors=e.asm.__wasm_call_ctors).apply(null,arguments)},e._getModelBufferMemoryOffset=function(){return(e._getModelBufferMemoryOffset=e.asm.getModelBufferMemoryOffset).apply(null,arguments)},e._getInputMemoryOffset=function(){return(e._getInputMemoryOffset=e.asm.getInputMemoryOffset).apply(null,arguments)},e._getInputHeight=function(){return(e._getInputHeight=e.asm.getInputHeight).apply(null,arguments)},e._getInputWidth=function(){return(e._getInputWidth=e.asm.getInputWidth).apply(null,arguments)},e._getInputChannelCount=function(){return(e._getInputChannelCount=e.asm.getInputChannelCount).apply(null,arguments)},e._getOutputMemoryOffset=function(){return(e._getOutputMemoryOffset=e.asm.getOutputMemoryOffset).apply(null,arguments)},e._getOutputHeight=function(){return(e._getOutputHeight=e.asm.getOutputHeight).apply(null,arguments)},e._getOutputWidth=function(){return(e._getOutputWidth=e.asm.getOutputWidth).apply(null,arguments)},e._getOutputChannelCount=function(){return(e._getOutputChannelCount=e.asm.getOutputChannelCount).apply(null,arguments)},e._loadModel=function(){return(e._loadModel=e.asm.loadModel).apply(null,arguments)},e._runInference=function(){return(e._runInference=e.asm.runInference).apply(null,arguments)},e._malloc=function(){return(e._malloc=e.asm.malloc).apply(null,arguments)},e.___errno_location=function(){return(e.___errno_location=e.asm.__errno_location).apply(null,arguments)},e.___dl_seterr=function(){return(e.___dl_seterr=e.asm.__dl_seterr).apply(null,arguments)},e.stackSave=function(){return(e.stackSave=e.asm.stackSave).apply(null,arguments)},e.stackRestore=function(){return(e.stackRestore=e.asm.stackRestore).apply(null,arguments)},e.stackAlloc=function(){return(e.stackAlloc=e.asm.stackAlloc).apply(null,arguments)},e.dynCall_jjj=function(){return(e.dynCall_jjj=e.asm.dynCall_jjj).apply(null,arguments)},e.dynCall_jiii=function(){return(e.dynCall_jiii=e.asm.dynCall_jiii).apply(null,arguments)},e.dynCall_iiiijj=function(){return(e.dynCall_iiiijj=e.asm.dynCall_iiiijj).apply(null,arguments)},e.dynCall_viijj=function(){return(e.dynCall_viijj=e.asm.dynCall_viijj).apply(null,arguments)},e.dynCall_viiijjj=function(){return(e.dynCall_viiijjj=e.asm.dynCall_viiijjj).apply(null,arguments)},e.dynCall_iijjiiii=function(){return(e.dynCall_iijjiiii=e.asm.dynCall_iijjiiii).apply(null,arguments)},e.dynCall_jiji=function(){return(e.dynCall_jiji=e.asm.dynCall_jiji).apply(null,arguments)};var fe;K=function n(){fe||xe(),fe||(K=n)};function xe(n){if(V>0||(ae(),V>0))return;function o(){fe||(fe=!0,e.calledRun=!0,!T&&(F(),i(e),e.onRuntimeInitialized&&e.onRuntimeInitialized(),te()))}e.setStatus?(e.setStatus("Running..."),setTimeout(function(){setTimeout(function(){e.setStatus("")},1),o()},1)):o()}if(e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);e.preInit.length>0;)e.preInit.pop()();return xe(),r.ready}})(),jt=(()=>{var t="https://rtk-assets.realtime.cloudflare.com/virtual-bg/";return function(r){r=r||{};var e=typeof r!="undefined"?r:{},i,s;e.ready=new Promise(function(n,o){i=n,s=o});var c=Object.assign({},e),f="./this.program",p=(n,o)=>{throw o},l=!0,m="";function h(n){return e.locateFile?e.locateFile(n,m):m+n}var u;typeof document!="undefined"&&document.currentScript&&(m=document.currentScript.src),m=t,m.indexOf("blob:")!==0?m=m.substr(0,m.replace(/[?#].*/,"").lastIndexOf("/")+1):m="";var w=e.print||console.log.bind(console),E=e.printErr||console.warn.bind(console);Object.assign(e,c),c=null,e.arguments&&e.arguments,e.thisProgram&&(f=e.thisProgram),e.quit&&(p=e.quit);var _;e.wasmBinary&&(_=e.wasmBinary);var R=e.noExitRuntime||!0;typeof WebAssembly!="object"&&Y("no native wasm support detected");var b,T=!1,U=typeof TextDecoder!="undefined"?new TextDecoder("utf8"):void 0;function W(n,o,d){for(var v=o+d,y=o;n[y]&&!(y>=v);)++y;if(y-o>16&&n.buffer&&U)return U.decode(n.subarray(o,y));for(var M="";o<y;){var g=n[o++];if(!(g&128)){M+=String.fromCharCode(g);continue}var S=n[o++]&63;if((g&224)==192){M+=String.fromCharCode((g&31)<<6|S);continue}var k=n[o++]&63;if((g&240)==224?g=(g&15)<<12|S<<6|k:g=(g&7)<<18|S<<12|k<<6|n[o++]&63,g<65536)M+=String.fromCharCode(g);else{var Z=g-65536;M+=String.fromCharCode(55296|Z>>10,56320|Z&1023)}}return M}var j,C,B,x;function q(n){j=n,e.HEAP8=C=new Int8Array(n),e.HEAP16=new Int16Array(n),e.HEAP32=new Int32Array(n),e.HEAPU8=B=new Uint8Array(n),e.HEAPU16=new Uint16Array(n),e.HEAPU32=x=new Uint32Array(n),e.HEAPF32=new Float32Array(n),e.HEAPF64=new Float64Array(n)}e.INITIAL_MEMORY;var H=[],N=[],A=[];function L(){return R}function ae(){if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)re(e.preRun.shift());he(H)}function F(){he(N)}function te(){if(e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;)ne(e.postRun.shift());he(A)}function re(n){H.unshift(n)}function J(n){N.unshift(n)}function ne(n){A.unshift(n)}var V=0,K=null;function Ee(n){V++,e.monitorRunDependencies&&e.monitorRunDependencies(V)}function Le(n){if(V--,e.monitorRunDependencies&&e.monitorRunDependencies(V),V==0&&K){var o=K;K=null,o()}}function Y(n){e.onAbort&&e.onAbort(n),n="Aborted("+n+")",E(n),T=!0,n+=". Build with -sASSERTIONS for more info.";var o=new WebAssembly.RuntimeError(n);throw s(o),o}var De="data:application/octet-stream;base64,";function Re(n){return n.startsWith(De)}var I;I="tflite-simd.wasm",Re(I)||(I=h(I));function Me(n){try{if(n==I&&_)return new Uint8Array(_);throw"both async and sync fetching of the wasm failed"}catch(o){Y(o)}}function je(){return!_&&l&&typeof fetch=="function"?fetch(I,{credentials:"same-origin"}).then(function(n){if(!n.ok)throw"failed to load wasm binary file at '"+I+"'";return n.arrayBuffer()}).catch(function(){return Me(I)}):Promise.resolve().then(function(){return Me(I)})}function Ne(){var n={env:Te,wasi_snapshot_preview1:Te};function o(g,S){var k=g.exports;e.asm=k,b=e.asm.memory,q(b.buffer),e.asm.__indirect_function_table,J(e.asm.__wasm_call_ctors),Le()}Ee();function d(g){o(g.instance)}function v(g){return je().then(function(S){return WebAssembly.instantiate(S,n)}).then(function(S){return S}).then(g,function(S){E("failed to asynchronously prepare wasm: "+S),Y(S)})}function y(){return!_&&typeof WebAssembly.instantiateStreaming=="function"&&!Re(I)&&typeof fetch=="function"?fetch(I,{credentials:"same-origin"}).then(function(g){var S=WebAssembly.instantiateStreaming(g,n);return S.then(d,function(k){return E("wasm streaming compile failed: "+k),E("falling back to ArrayBuffer instantiation"),v(d)})}):v(d)}if(e.instantiateWasm)try{var M=e.instantiateWasm(n,o);return M}catch(g){E("Module.instantiateWasm callback failed with error: "+g),s(g)}return y().catch(s),{}}function We(n){this.name="ExitStatus",this.message="Program terminated with exit("+n+")",this.status=n}function he(n){for(;n.length>0;)n.shift()(e)}function He(n){}var Se="To use dlopen, you need enable dynamic linking, see https://github.com/emscripten-core/emscripten/wiki/Linking";function Ve(n,o){Y(Se)}function Ge(n,o){Y(Se)}var Xe=!0;function ze(){return Xe}function qe(n,o,d,v,y,M){return-52}function Ke(n,o,d,v,y,M){}function Ye(){Y("")}function Qe(){return Date.now()}function Ae(){return 2147483648}function $e(){return Ae()}var Fe;Fe=()=>performance.now();function Je(n,o,d){B.copyWithin(n,o,o+d)}function Ze(n){try{return b.grow(n-j.byteLength+65535>>>16),q(b.buffer),1}catch{}}function et(n){var o=B.length;n=n>>>0;var d=Ae();if(n>d)return!1;let v=(k,Z)=>k+(Z-k%Z)%Z;for(var y=1;y<=4;y*=2){var M=o*(1+.2/y);M=Math.min(M,n+100663296);var g=Math.min(d,v(Math.max(n,M),65536)),S=Ze(g);if(S)return!0}return!1}var _e={};function tt(){return f||"./this.program"}function ie(){if(!ie.strings){var n=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",o={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:n,_:tt()};for(var d in _e)_e[d]===void 0?delete o[d]:o[d]=_e[d];var v=[];for(var d in o)v.push(d+"="+o[d]);ie.strings=v}return ie.strings}function rt(n,o,d){for(var v=0;v<n.length;++v)C[o++>>0]=n.charCodeAt(v);d||(C[o>>0]=0)}function nt(n,o){var d=0;return ie().forEach(function(v,y){var M=o+d;x[n+y*4>>2]=M,rt(v,M),d+=v.length+1}),0}function it(n,o){var d=ie();x[n>>2]=d.length;var v=0;return d.forEach(function(y){v+=y.length+1}),x[o>>2]=v,0}function ot(n){L()||(e.onExit&&e.onExit(n),T=!0),p(n,new We(n))}function st(n,o){ot(n)}var at=st;function ut(n){return 52}function ct(n,o,d,v,y){return 70}var ft=[null,[],[]];function dt(n,o){var d=ft[n];o===0||o===10?((n===1?w:E)(W(d,0)),d.length=0):d.push(o)}function mt(n,o,d,v){for(var y=0,M=0;M<d;M++){var g=x[o>>2],S=x[o+4>>2];o+=8;for(var k=0;k<S;k++)dt(n,B[g+k]);y+=S}return x[v>>2]=y,0}function lt(){if(typeof crypto=="object"&&typeof crypto.getRandomValues=="function"){var n=new Uint8Array(1);return()=>(crypto.getRandomValues(n),n[0])}else return()=>Y("randomDevice")}function ce(n,o){ce.randomDevice||(ce.randomDevice=lt());for(var d=0;d<o;d++)C[n+d>>0]=ce.randomDevice();return 0}var Te={_dlinit:He,_dlopen_js:Ve,_dlsym_js:Ge,_emscripten_get_now_is_monotonic:ze,_mmap_js:qe,_munmap_js:Ke,abort:Ye,emscripten_date_now:Qe,emscripten_get_heap_max:$e,emscripten_get_now:Fe,emscripten_memcpy_big:Je,emscripten_resize_heap:et,environ_get:nt,environ_sizes_get:it,exit:at,fd_close:ut,fd_seek:ct,fd_write:mt,getentropy:ce};Ne(),e.___wasm_call_ctors=function(){return(e.___wasm_call_ctors=e.asm.__wasm_call_ctors).apply(null,arguments)},e._getModelBufferMemoryOffset=function(){return(e._getModelBufferMemoryOffset=e.asm.getModelBufferMemoryOffset).apply(null,arguments)},e._getInputMemoryOffset=function(){return(e._getInputMemoryOffset=e.asm.getInputMemoryOffset).apply(null,arguments)},e._getInputHeight=function(){return(e._getInputHeight=e.asm.getInputHeight).apply(null,arguments)},e._getInputWidth=function(){return(e._getInputWidth=e.asm.getInputWidth).apply(null,arguments)},e._getInputChannelCount=function(){return(e._getInputChannelCount=e.asm.getInputChannelCount).apply(null,arguments)},e._getOutputMemoryOffset=function(){return(e._getOutputMemoryOffset=e.asm.getOutputMemoryOffset).apply(null,arguments)},e._getOutputHeight=function(){return(e._getOutputHeight=e.asm.getOutputHeight).apply(null,arguments)},e._getOutputWidth=function(){return(e._getOutputWidth=e.asm.getOutputWidth).apply(null,arguments)},e._getOutputChannelCount=function(){return(e._getOutputChannelCount=e.asm.getOutputChannelCount).apply(null,arguments)},e._loadModel=function(){return(e._loadModel=e.asm.loadModel).apply(null,arguments)},e._runInference=function(){return(e._runInference=e.asm.runInference).apply(null,arguments)},e._malloc=function(){return(e._malloc=e.asm.malloc).apply(null,arguments)},e.___errno_location=function(){return(e.___errno_location=e.asm.__errno_location).apply(null,arguments)},e.___dl_seterr=function(){return(e.___dl_seterr=e.asm.__dl_seterr).apply(null,arguments)},e.stackSave=function(){return(e.stackSave=e.asm.stackSave).apply(null,arguments)},e.stackRestore=function(){return(e.stackRestore=e.asm.stackRestore).apply(null,arguments)},e.stackAlloc=function(){return(e.stackAlloc=e.asm.stackAlloc).apply(null,arguments)},e.dynCall_jjj=function(){return(e.dynCall_jjj=e.asm.dynCall_jjj).apply(null,arguments)},e.dynCall_jiii=function(){return(e.dynCall_jiii=e.asm.dynCall_jiii).apply(null,arguments)},e.dynCall_iiiijj=function(){return(e.dynCall_iiiijj=e.asm.dynCall_iiiijj).apply(null,arguments)},e.dynCall_viijj=function(){return(e.dynCall_viijj=e.asm.dynCall_viijj).apply(null,arguments)},e.dynCall_viiijjj=function(){return(e.dynCall_viiijjj=e.asm.dynCall_viiijjj).apply(null,arguments)},e.dynCall_iijjiiii=function(){return(e.dynCall_iijjiiii=e.asm.dynCall_iijjiiii).apply(null,arguments)},e.dynCall_jiji=function(){return(e.dynCall_jiji=e.asm.dynCall_jiji).apply(null,arguments)};var fe;K=function n(){fe||xe(),fe||(K=n)};function xe(n){if(V>0||(ae(),V>0))return;function o(){fe||(fe=!0,e.calledRun=!0,!T&&(F(),i(e),e.onRuntimeInitialized&&e.onRuntimeInitialized(),te()))}e.setStatus?(e.setStatus("Running..."),setTimeout(function(){setTimeout(function(){e.setStatus("")},1),o()},1)):o()}if(e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);e.preInit.length>0;)e.preInit.pop()();return xe(),r.ready}})();async function Nt(t){let r=null,e=null,i=null,s=!1;async function c(){r=await Dt();try{e=await jt(),s=!0,t.backend="wasmSimd"}catch(p){console.warn("Failed to create TFLite SIMD WebAssembly module.",p)}}await c();async function f(){if(!r||s&&!e||!s&&t.backend==="wasmSimd"||t.model!=="meet"&&t.model!=="mlkit")return;i=null;const p=t.backend==="wasmSimd"?e:r;if(!p)throw new Error(`TFLite backend unavailable: ${t.backend}`);const l=bt(t.model,t.inputResolution),h=await(await fetch(`https://rtk-assets.realtime.cloudflare.com/virtual-bg/tf-assets/models/${l}.tflite`)).arrayBuffer(),u=p._getModelBufferMemoryOffset();p.HEAPU8.set(new Uint8Array(h),u),p._loadModel(h.byteLength),i=p}return await f(),{tflite:i,isSIMDSupported:s}}const Ie=class{constructor(r,e){ge(this,we,void 0);ge(this,ye,void 0);de(this,we,r),de(this,ye,e)}static async init({meeting:r,segmentationConfig:e,postProcessingConfig:i}){this.isSupported()||console.error("Initialising it in an unsupported environment, the middleware might not work"),window.addEventListener("error",l=>{var m;!((m=l.filename)!=null&&m.includes("localhost"))&&l.lineno!==0&&console.error("RealtimeKitVideoBackgroundTransformer::UnhandledError",l.error)}),window.addEventListener("unhandledrejection",l=>{console.error("RealtimeKitVideoBackgroundTransformer::UnhandledRejection",l.reason)});const s={model:"mlkit",backend:"wasmSimd",inputResolution:"256x256",pipeline:"webgl2",targetFps:35,deferInputResizing:!0,...e||{}};Ce().getEngineName()==="WebKit"&&(s.pipeline="canvas2dCpu");const f={smoothSegmentationMask:!0,jointBilateralFilter:{sigmaSpace:1,sigmaColor:.1},coverage:[.5,.75],lightWrapping:.3,blendMode:"screen",...i||{}};await r.self.setVideoMiddlewareGlobalConfig({disablePerFrameCanvasRendering:!0});const{tflite:p}=await Nt(s);return new Ie(await Be.init({meeting:r,segmentationConfig:s,postProcessingConfig:f,tflite:p}),await Pe.init({meeting:r,segmentationConfig:s,postProcessingConfig:f,tflite:p}))}static isSupported(){var e;let r=!1;try{const i=Ce(),s=document.createElement("canvas"),c=s.getContext("webgl2",{})||s.getContext("webgl",{}),f=+((e=i.getBrowserVersion())==null?void 0:e.split(".")[0]);if(!c||i.getOSName()==="iOS"||i.getBrowserName()==="Safari"&&f<17)return!1;r=!0}catch{r=!1}return r}async createStaticBackgroundVideoMiddleware(r){return await O(this,we).createStaticBackgroundImageVideoMiddleware(r)}async createBackgroundBlurVideoMiddleware(r=50){return O(this,ye).createBackgroundBlurVideoMiddleware(r)}destruct(){O(this,we).destruct(),O(this,ye).destruct()}};let ke=Ie;return we=new WeakMap,ye=new WeakMap,ke}();
package/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@cloudflare/realtimekit-virtual-background",
3
- "version": "0.0.2",
3
+ "version": "0.0.3-staging.1",
4
+ "browser": "./dist/index.iife.js",
4
5
  "main": "./dist/index.cjs.js",
5
6
  "module": "./dist/index.es.js",
6
7
  "exports": {
@@ -12,13 +13,21 @@
12
13
  },
13
14
  "types": "./types/index.d.ts",
14
15
  "bugs": {
15
- "url": "https://docs.dyte.in/discuss"
16
+ "url": "https://community.cloudflare.com/c/developers/cloudflare-realtime/101"
16
17
  },
17
18
  "private": false,
18
19
  "dependencies": {},
20
+ "peerDependencies": {
21
+ "@cloudflare/realtimekit": ">=1.0.1",
22
+ "bowser": "^2.11.0"
23
+ },
19
24
  "publishConfig": {
20
- "tag": "staging"
25
+ "access": "public"
21
26
  },
27
+ "files": [
28
+ "dist",
29
+ "types"
30
+ ],
22
31
  "scripts": {
23
32
  "postpublish": "mv package.json.bak package.json"
24
33
  }
package/favicon.svg DELETED
@@ -1,15 +0,0 @@
1
- <svg width="410" height="404" viewBox="0 0 410 404" fill="none" xmlns="http://www.w3.org/2000/svg">
2
- <path d="M399.641 59.5246L215.643 388.545C211.844 395.338 202.084 395.378 198.228 388.618L10.5817 59.5563C6.38087 52.1896 12.6802 43.2665 21.0281 44.7586L205.223 77.6824C206.398 77.8924 207.601 77.8904 208.776 77.6763L389.119 44.8058C397.439 43.2894 403.768 52.1434 399.641 59.5246Z" fill="url(#paint0_linear)"/>
3
- <path d="M292.965 1.5744L156.801 28.2552C154.563 28.6937 152.906 30.5903 152.771 32.8664L144.395 174.33C144.198 177.662 147.258 180.248 150.51 179.498L188.42 170.749C191.967 169.931 195.172 173.055 194.443 176.622L183.18 231.775C182.422 235.487 185.907 238.661 189.532 237.56L212.947 230.446C216.577 229.344 220.065 232.527 219.297 236.242L201.398 322.875C200.278 328.294 207.486 331.249 210.492 326.603L212.5 323.5L323.454 102.072C325.312 98.3645 322.108 94.137 318.036 94.9228L279.014 102.454C275.347 103.161 272.227 99.746 273.262 96.1583L298.731 7.86689C299.767 4.27314 296.636 0.855181 292.965 1.5744Z" fill="url(#paint1_linear)"/>
4
- <defs>
5
- <linearGradient id="paint0_linear" x1="6.00017" y1="32.9999" x2="235" y2="344" gradientUnits="userSpaceOnUse">
6
- <stop stop-color="#41D1FF"/>
7
- <stop offset="1" stop-color="#BD34FE"/>
8
- </linearGradient>
9
- <linearGradient id="paint1_linear" x1="194.651" y1="8.81818" x2="236.076" y2="292.989" gradientUnits="userSpaceOnUse">
10
- <stop stop-color="#FFEA83"/>
11
- <stop offset="0.0833333" stop-color="#FFDD35"/>
12
- <stop offset="1" stop-color="#FFA800"/>
13
- </linearGradient>
14
- </defs>
15
- </svg>