@cloudflare/realtimekit-virtual-background 0.0.1 → 0.0.2-staging.2
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 +149 -0
- package/dist/index.cjs.js +231 -0
- package/dist/index.es.js +4266 -0
- package/dist/index.iife.js +231 -0
- package/favicon.svg +15 -0
- package/package.json +25 -5
- package/types/ImageBackgroundTransformer.d.ts +9 -0
- package/types/SimpleBackgroundTransformer.d.ts +9 -0
- package/types/client/RealtimeKitVideoBackgroundTransformer.d.ts +49 -0
- package/types/common/BackgroundTransformer.d.ts +10 -0
- package/types/core/helpers/backgroundHelper.d.ts +6 -0
- package/types/core/helpers/postProcessingHelper.d.ts +12 -0
- package/types/core/helpers/renderingPipelineHelper.d.ts +6 -0
- package/types/core/helpers/segmentationHelper.d.ts +16 -0
- package/types/core/helpers/sourceHelper.d.ts +11 -0
- package/types/core/hooks/useTFLite.d.ts +21 -0
- package/types/index.d.ts +2 -0
- package/types/pipelines/canvas2d/canvas2dPipeline.d.ts +11 -0
- package/types/pipelines/helpers/webglHelper.d.ts +18 -0
- package/types/pipelines/webgl2/backgroundBlurStage.d.ts +7 -0
- package/types/pipelines/webgl2/backgroundImageStage.d.ts +10 -0
- package/types/pipelines/webgl2/jointBilateralFilterStage.d.ts +7 -0
- package/types/pipelines/webgl2/loadSegmentationStage.d.ts +6 -0
- package/types/pipelines/webgl2/resizingStage.d.ts +7 -0
- package/types/pipelines/webgl2/softmaxStage.d.ts +6 -0
- package/types/pipelines/webgl2/webgl2Pipeline.d.ts +11 -0
- package/types/tflite/tflite-simd.d.ts +2 -0
- package/types/tflite/tflite.d.ts +2 -0
- package/types/utils/browser.d.ts +3 -0
- package/types/utils/image.d.ts +2 -0
package/README.md
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
<!-- PROJECT LOGO -->
|
|
2
|
+
<p align="center">
|
|
3
|
+
<a href="https://realtime.cloudflare.com">
|
|
4
|
+
<img src="https://docs.realtime.cloudflare.com/logo/cf.svg" alt="Logo" width="120">
|
|
5
|
+
</a>
|
|
6
|
+
|
|
7
|
+
<h3 align="center">RealtimeKit Video Background Manager</h3>
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
A Package that allows ease of use for RealtimeKit's video middlewares
|
|
11
|
+
<br />
|
|
12
|
+
<a href="https://docs.realtime.cloudflare.com"><strong>Explore the docs »</strong></a>
|
|
13
|
+
<br />
|
|
14
|
+
<br />
|
|
15
|
+
<a href="https://demo.realtime.cloudflare.com/">View Demo</a>
|
|
16
|
+
·
|
|
17
|
+
<a href="https://dyte.io/contact">Report Bug</a>
|
|
18
|
+
·
|
|
19
|
+
<a href="https://dyte.io/contact">Request Feature</a>
|
|
20
|
+
</p>
|
|
21
|
+
</p>
|
|
22
|
+
|
|
23
|
+
<!-- TABLE OF CONTENTS -->
|
|
24
|
+
|
|
25
|
+
## Table of Contents
|
|
26
|
+
|
|
27
|
+
* [About the Project](#about-the-project)
|
|
28
|
+
* [Built With](#built-with)
|
|
29
|
+
* [Getting Started](#getting-started)
|
|
30
|
+
* [Prerequisites](#prerequisites)
|
|
31
|
+
* [Installation](#installation)
|
|
32
|
+
* [Usage](#usage)
|
|
33
|
+
* [Contributing](#contributing)
|
|
34
|
+
* [License](#license)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
<!-- ABOUT THE PROJECT -->
|
|
39
|
+
## About The Project
|
|
40
|
+
|
|
41
|
+
The goal of Video Background Transformer is to create RealtimeKit Meetings' VideoMiddlewares with ease and make it fun to play around with.
|
|
42
|
+
|
|
43
|
+
### Built With
|
|
44
|
+
|
|
45
|
+
* [RealtimeKit](https://realtime.cloudflare.com/)
|
|
46
|
+
* [Typescript](https://typescriptlang.org)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
<!-- GETTING STARTED -->
|
|
50
|
+
## Getting Started
|
|
51
|
+
|
|
52
|
+
### Prerequisites
|
|
53
|
+
* npm
|
|
54
|
+
* Web Core Version >= 2.0 (Web Core, React Web Core, Angular Web Core etc.)
|
|
55
|
+
* UI Kit Version >= 2.0 (UI Kit, React UI Kit, Angular UI Kit etc.)
|
|
56
|
+
|
|
57
|
+
### Installation
|
|
58
|
+
|
|
59
|
+
```sh
|
|
60
|
+
npm install @cloudflare/realtimekit-virtual-background
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
<!-- USAGE EXAMPLES -->
|
|
66
|
+
## Usage
|
|
67
|
+
|
|
68
|
+
**_Note:_** Make sure that you are using the 2.x versions of Web Core & UI Kit.
|
|
69
|
+
|
|
70
|
+
Disable the default per frame rendering of video middleware to improve speed and quality by letting this middleware control it on its own.
|
|
71
|
+
|
|
72
|
+
```ts
|
|
73
|
+
await meeting.self.setVideoMiddlewareGlobalConfig({
|
|
74
|
+
disablePerFrameCanvasRendering: true
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
A `videoBackgroundTransformer` object can be created using the `RealtimeKitVideoBackgroundTransformer.init({meeting: meeting})` method.
|
|
79
|
+
|
|
80
|
+
```ts
|
|
81
|
+
const videoBackgroundTransformer = await RealtimeKitVideoBackgroundTransformer.init({
|
|
82
|
+
meeting,
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Types of middlewares exposed by `videoBackgroundTransformer`:
|
|
87
|
+
1. ```createStaticBackgroundVideoMiddleware``` expects an ```imageUrl``` as a parameter and then creates the image the background for the current user.
|
|
88
|
+
```ts
|
|
89
|
+
meeting.self.addVideoMiddleware(
|
|
90
|
+
await videoBackgroundTransformer.createStaticBackgroundVideoMiddleware(imageUrl)
|
|
91
|
+
);
|
|
92
|
+
```
|
|
93
|
+
2. ```createBackgroundBlurVideoMiddleware``` expects ```blurLength``` as a parameter (4px by default) and blurs the background of the user by the given blurLength.
|
|
94
|
+
```ts
|
|
95
|
+
meeting.self.addVideoMiddleware(
|
|
96
|
+
await videoBackgroundTransformer.createBackgroundBlurVideoMiddleware(10)
|
|
97
|
+
);
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**_Note:_** Some browsers or their old versions might not have support for WebGL or the browser APIs that this package uses. We would recommend checking the support beforehand using:
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
if(RealtimeKitVideoBackgroundTransformer.isSupported()){
|
|
104
|
+
const videoBackgroundTransformer = await RealtimeKitVideoBackgroundTransformer.init({
|
|
105
|
+
meeting: meeting,
|
|
106
|
+
});
|
|
107
|
+
meeting.self.addVideoMiddleware(
|
|
108
|
+
await videoBackgroundTransformer.createStaticBackgroundVideoMiddleware(`REPLACE_THIS_WITH_IMAGE_URL`)
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**_Note:_** Image URLs must allow CORS to avoid tainting the canvas. You can find such images on <https://unsplash.com/> & <https://imgur.com>.
|
|
114
|
+
|
|
115
|
+
If in case you want to tweak the segmentation for better, sharper results, Please pass the desired segmentation config while initialising RealtimeKitVideoBackgroundTransformer.
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
const videoBackgroundTransformer = await RealtimeKitVideoBackgroundTransformer.init({
|
|
119
|
+
meeting,
|
|
120
|
+
segmentationConfig: {
|
|
121
|
+
model: 'mlkit', // 'meet' | 'mlkit'
|
|
122
|
+
backend: 'wasmSimd',
|
|
123
|
+
inputResolution: '256x256', // '256x144' for meet
|
|
124
|
+
pipeline: 'webgl2', // 'webgl2' | 'canvas2dCpu' // canvas2dCpu gives sharper blur, webgl2 is faster.
|
|
125
|
+
targetFps: 35,
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
<!-- CONTRIBUTING -->
|
|
131
|
+
## Contributing
|
|
132
|
+
|
|
133
|
+
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**.
|
|
134
|
+
|
|
135
|
+
1. Fork the Project
|
|
136
|
+
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
|
|
137
|
+
3. Commit your Changes (`git commit -m 'feat: Add some AmazingFeature'`)
|
|
138
|
+
4. Push to the Branch (`git push -u origin feature/AmazingFeature`)
|
|
139
|
+
5. Open a Pull Request
|
|
140
|
+
|
|
141
|
+
<!-- LICENSE -->
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
Distributed under the MIT License. See [`LICENSE`](./LICENSE) for more information.
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
<!-- MARKDOWN LINKS & IMAGES -->
|
|
149
|
+
<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"use strict";var dt=(t,r,e)=>{if(!r.has(t))throw TypeError("Cannot "+e)};var O=(t,r,e)=>(dt(t,r,"read from private field"),e?e.call(t):r.get(t)),me=(t,r,e)=>{if(r.has(t))throw TypeError("Cannot add the same private member more than once");r instanceof WeakSet?r.add(t):r.set(t,e)},ae=(t,r,e,i)=>(dt(t,r,"write to private field"),i?i.call(t,e):r.set(t,e),e);class lt{constructor(){this.createCameraVideoElement=async r=>{const e=r,{height:i,width:s}=e.getSettings();if(i===void 0||s===void 0)throw Error("Background removal can't commence as Height and Width of the video feed is undefined");const c=document.createElement("video");c.width=s,c.height=i,c.srcObject=new MediaStream([e]),c.autoplay=!0,c.muted=!0,c.playsInline=!0,c.controls=!0;try{await c.play()}catch{console.warn("RealtimeKitVideoBackgroundTransformer:: Couldn't play raw video feed in detached mode")}return c}}}const pt=t=>new Promise((r,e)=>{const i=new Image;i.onload=()=>r(i),i.onerror=e,i.src=t,i.crossOrigin="anonymous"}),vt=t=>new Promise((r,e)=>{const i=document.createElement("canvas"),s=i.getContext("2d");i.width=t.videoWidth,i.height=t.videoHeight,s.drawImage(t,0,0,i.width,i.height);const c=new Image;c.onload=()=>r(c),c.onerror=e,c.src=i.toDataURL("image/jpeg"),c.crossOrigin="anonymous"}),ve={"640x360":[640,360],"256x256":[256,256],"256x144":[256,144],"160x96":[160,96]};function bt(t,r){switch(t){case"meet":return r==="256x144"?"segm_full_v679":"segm_lite_v681";case"mlkit":return"selfiesegmentation_mlkit-256x256-2021_01_19-v1215.f16";default:throw new Error(`No TFLite file for this segmentation model: ${t}`)}}const ne=String.raw;function le(t,r,e,i,s){const c=wt(t,r,e),f=t.getAttribLocation(c,"a_position");t.enableVertexAttribArray(f),t.bindBuffer(t.ARRAY_BUFFER,i),t.vertexAttribPointer(f,2,t.FLOAT,!1,0,0);const p=t.getAttribLocation(c,"a_texCoord");return t.enableVertexAttribArray(p),t.bindBuffer(t.ARRAY_BUFFER,s),t.vertexAttribPointer(p,2,t.FLOAT,!1,0,0),c}function wt(t,r,e){const i=t.createProgram();if(t.attachShader(i,r),t.attachShader(i,e),t.linkProgram(i),!t.getProgramParameter(i,t.LINK_STATUS))throw new Error(`Could not link WebGL program: ${t.getProgramInfoLog(i)}`);return i}function ie(t,r,e){const i=t.createShader(r);if(t.shaderSource(i,e),t.compileShader(i),!t.getShaderParameter(i,t.COMPILE_STATUS))throw new Error(`Could not compile shader: ${t.getShaderInfoLog(i)}`);return i}function ce(t,r,e,i,s=t.NEAREST,c=t.NEAREST){const f=t.createTexture();return t.bindTexture(t.TEXTURE_2D,f),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,s),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,c),t.texStorage2D(t.TEXTURE_2D,1,r,e,i),f}async function yt(t,r,e,i,s,c,f,p,l){const m=r.createBuffer();return r.bindBuffer(r.PIXEL_PACK_BUFFER,m),r.bufferData(r.PIXEL_PACK_BUFFER,l.byteLength,r.STREAM_READ),r.readPixels(e,i,s,c,f,p,0),r.bindBuffer(r.PIXEL_PACK_BUFFER,null),await Et(t,r,r.PIXEL_PACK_BUFFER,m,0,l),r.deleteBuffer(m),l}async function Et(t,r,e,i,s,c,f,p){const l=r.fenceSync(r.SYNC_GPU_COMMANDS_COMPLETE,0);r.flush();const m=await Rt(t,r,l);r.deleteSync(l),m!==r.WAIT_FAILED&&(r.bindBuffer(e,i),r.getBufferSubData(e,s,c,f,p),r.bindBuffer(e,null))}function Rt(t,r,e){return new Promise(i=>{function s(){const c=r.clientWaitSync(e,0,0);if(c===r.WAIT_FAILED){i(c);return}if(c===r.TIMEOUT_EXPIRED){t.setTimeout(s,0);return}i(c)}t.setTimeout(s,0)})}function Mt(t,r,e,i,s,c,f){const p=St(t,r,e,i,s,c,f),l=At(t,e,i,c);function m(){p.render(),l.render()}function h(w){l.updateCoverage(w)}function u(){l.cleanUp(),p.cleanUp()}return{render:m,updateCoverage:h,cleanUp:u}}function St(t,r,e,i,s,c,f){const p=ne`#version 300 es
|
|
2
|
+
|
|
3
|
+
precision highp float;
|
|
4
|
+
|
|
5
|
+
uniform sampler2D u_inputFrame;
|
|
6
|
+
uniform sampler2D u_personMask;
|
|
7
|
+
uniform vec2 u_texelSize;
|
|
8
|
+
uniform float u_blurAmount;
|
|
9
|
+
|
|
10
|
+
in vec2 v_texCoord;
|
|
11
|
+
|
|
12
|
+
out vec4 outColor;
|
|
13
|
+
|
|
14
|
+
const float offset[5] = float[](0.0, 1.0, 2.0, 3.0, 4.0);
|
|
15
|
+
const float weight[5] = float[](0.2270270270, 0.1945945946, 0.1216216216,
|
|
16
|
+
0.0540540541, 0.0162162162);
|
|
17
|
+
|
|
18
|
+
void main() {
|
|
19
|
+
vec4 centerColor = texture(u_inputFrame, v_texCoord);
|
|
20
|
+
float personMask = texture(u_personMask, v_texCoord).a;
|
|
21
|
+
|
|
22
|
+
vec4 frameColor = centerColor * weight[0] * (1.0 - personMask);
|
|
23
|
+
|
|
24
|
+
for (int i = 1; i < 5; i++) {
|
|
25
|
+
vec2 offset = vec2(offset[i]) * u_texelSize * u_blurAmount;
|
|
26
|
+
|
|
27
|
+
vec2 texCoord = v_texCoord + offset;
|
|
28
|
+
frameColor += texture(u_inputFrame, texCoord) * weight[i] *
|
|
29
|
+
(1.0 - texture(u_personMask, texCoord).a);
|
|
30
|
+
|
|
31
|
+
texCoord = v_texCoord - offset;
|
|
32
|
+
frameColor += texture(u_inputFrame, texCoord) * weight[i] *
|
|
33
|
+
(1.0 - texture(u_personMask, texCoord).a);
|
|
34
|
+
}
|
|
35
|
+
outColor = vec4(frameColor.rgb + (1.0 - frameColor.a) * centerColor.rgb, 1.0);
|
|
36
|
+
}
|
|
37
|
+
`,l=.5,m=c.width*l,h=c.height*l,u=1/m,w=1/h,E=ie(t,t.FRAGMENT_SHADER,p),_=le(t,r,E,e,i),R=t.getUniformLocation(_,"u_inputFrame"),b=t.getUniformLocation(_,"u_personMask"),T=t.getUniformLocation(_,"u_texelSize"),U=t.getUniformLocation(_,"u_blurAmount"),W=ce(t,t.RGBA8,m,h,t.NEAREST,t.LINEAR),D=ce(t,t.RGBA8,m,h,t.NEAREST,t.LINEAR),C=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,C),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,W,0);const B=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,B),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,D,0),t.useProgram(_);const x=Math.max(0,Math.min(f.blurLength/10,10));t.uniform1f(U,x),t.uniform1i(b,1);function G(){t.viewport(0,0,m,h),t.useProgram(_),t.uniform1i(R,0),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,s);for(let j=0;j<3;j++)t.uniform2f(T,0,w),t.bindFramebuffer(t.FRAMEBUFFER,C),t.drawArrays(t.TRIANGLE_STRIP,0,4),t.activeTexture(t.TEXTURE2),t.bindTexture(t.TEXTURE_2D,W),t.uniform1i(R,2),t.uniform2f(T,u,0),t.bindFramebuffer(t.FRAMEBUFFER,B),t.drawArrays(t.TRIANGLE_STRIP,0,4),t.bindTexture(t.TEXTURE_2D,D)}function H(){t.deleteFramebuffer(B),t.deleteFramebuffer(C),t.deleteTexture(D),t.deleteTexture(W),t.deleteProgram(_),t.deleteShader(E)}return{render:G,cleanUp:H}}function At(t,r,e,i){const s=ne`#version 300 es
|
|
38
|
+
|
|
39
|
+
in vec2 a_position;
|
|
40
|
+
in vec2 a_texCoord;
|
|
41
|
+
|
|
42
|
+
out vec2 v_texCoord;
|
|
43
|
+
|
|
44
|
+
void main() {
|
|
45
|
+
// Flipping Y is required when rendering to canvas
|
|
46
|
+
gl_Position = vec4(a_position * vec2(1.0, -1.0), 0.0, 1.0);
|
|
47
|
+
v_texCoord = a_texCoord;
|
|
48
|
+
}
|
|
49
|
+
`,c=ne`#version 300 es
|
|
50
|
+
|
|
51
|
+
precision highp float;
|
|
52
|
+
|
|
53
|
+
uniform sampler2D u_inputFrame;
|
|
54
|
+
uniform sampler2D u_personMask;
|
|
55
|
+
uniform sampler2D u_blurredInputFrame;
|
|
56
|
+
uniform vec2 u_coverage;
|
|
57
|
+
|
|
58
|
+
in vec2 v_texCoord;
|
|
59
|
+
|
|
60
|
+
out vec4 outColor;
|
|
61
|
+
|
|
62
|
+
void main() {
|
|
63
|
+
vec3 color = texture(u_inputFrame, v_texCoord).rgb;
|
|
64
|
+
vec3 blurredColor = texture(u_blurredInputFrame, v_texCoord).rgb;
|
|
65
|
+
float personMask = texture(u_personMask, v_texCoord).a;
|
|
66
|
+
personMask = smoothstep(u_coverage.x, u_coverage.y, personMask);
|
|
67
|
+
outColor = vec4(mix(blurredColor, color, personMask), 1.0);
|
|
68
|
+
}
|
|
69
|
+
`,{width:f,height:p}=i,l=ie(t,t.VERTEX_SHADER,s),m=ie(t,t.FRAGMENT_SHADER,c),h=le(t,l,m,r,e),u=t.getUniformLocation(h,"u_inputFrame"),w=t.getUniformLocation(h,"u_personMask"),E=t.getUniformLocation(h,"u_blurredInputFrame"),_=t.getUniformLocation(h,"u_coverage");t.useProgram(h),t.uniform1i(u,0),t.uniform1i(w,1),t.uniform1i(E,2),t.uniform2f(_,0,1);function R(){t.viewport(0,0,f,p),t.useProgram(h),t.bindFramebuffer(t.FRAMEBUFFER,null),t.drawArrays(t.TRIANGLE_STRIP,0,4)}function b(U){t.useProgram(h),t.uniform2f(_,U[0],U[1])}function T(){t.deleteProgram(h),t.deleteShader(m),t.deleteShader(l)}return{render:R,updateCoverage:b,cleanUp:T}}function Ft(t,r,e,i,s,c,f){const p=ne`#version 300 es
|
|
70
|
+
|
|
71
|
+
uniform vec2 u_backgroundScale;
|
|
72
|
+
uniform vec2 u_backgroundOffset;
|
|
73
|
+
|
|
74
|
+
in vec2 a_position;
|
|
75
|
+
in vec2 a_texCoord;
|
|
76
|
+
|
|
77
|
+
out vec2 v_texCoord;
|
|
78
|
+
out vec2 v_backgroundCoord;
|
|
79
|
+
|
|
80
|
+
void main() {
|
|
81
|
+
// Flipping Y is required when rendering to canvas
|
|
82
|
+
gl_Position = vec4(a_position * vec2(1.0, -1.0), 0.0, 1.0);
|
|
83
|
+
v_texCoord = a_texCoord;
|
|
84
|
+
v_backgroundCoord = a_texCoord * u_backgroundScale + u_backgroundOffset;
|
|
85
|
+
}
|
|
86
|
+
`,l=ne`#version 300 es
|
|
87
|
+
|
|
88
|
+
precision highp float;
|
|
89
|
+
|
|
90
|
+
uniform sampler2D u_inputFrame;
|
|
91
|
+
uniform sampler2D u_personMask;
|
|
92
|
+
uniform sampler2D u_background;
|
|
93
|
+
uniform vec2 u_coverage;
|
|
94
|
+
uniform float u_lightWrapping;
|
|
95
|
+
uniform float u_blendMode;
|
|
96
|
+
|
|
97
|
+
in vec2 v_texCoord;
|
|
98
|
+
in vec2 v_backgroundCoord;
|
|
99
|
+
|
|
100
|
+
out vec4 outColor;
|
|
101
|
+
|
|
102
|
+
vec3 screen(vec3 a, vec3 b) {
|
|
103
|
+
return 1.0 - (1.0 - a) * (1.0 - b);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
vec3 linearDodge(vec3 a, vec3 b) {
|
|
107
|
+
return a + b;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
void main() {
|
|
111
|
+
vec3 frameColor = texture(u_inputFrame, v_texCoord).rgb;
|
|
112
|
+
vec3 backgroundColor = texture(u_background, v_backgroundCoord).rgb;
|
|
113
|
+
float personMask = texture(u_personMask, v_texCoord).a;
|
|
114
|
+
float lightWrapMask = 1.0 - max(0.0, personMask - u_coverage.y) / (1.0 - u_coverage.y);
|
|
115
|
+
vec3 lightWrap = u_lightWrapping * lightWrapMask * backgroundColor;
|
|
116
|
+
frameColor = u_blendMode * linearDodge(frameColor, lightWrap) +
|
|
117
|
+
(1.0 - u_blendMode) * screen(frameColor, lightWrap);
|
|
118
|
+
personMask = smoothstep(u_coverage.x, u_coverage.y, personMask);
|
|
119
|
+
outColor = vec4(frameColor * personMask + backgroundColor * (1.0 - personMask), 1.0);
|
|
120
|
+
}
|
|
121
|
+
`,{width:m,height:h}=c,u=m/h,w=ie(t,t.VERTEX_SHADER,p),E=ie(t,t.FRAGMENT_SHADER,l),_=le(t,w,E,r,e),R=t.getUniformLocation(_,"u_backgroundScale"),b=t.getUniformLocation(_,"u_backgroundOffset"),T=t.getUniformLocation(_,"u_inputFrame"),U=t.getUniformLocation(_,"u_personMask"),W=t.getUniformLocation(_,"u_background"),D=t.getUniformLocation(_,"u_coverage"),C=t.getUniformLocation(_,"u_lightWrapping"),B=t.getUniformLocation(_,"u_blendMode");t.useProgram(_),t.uniform2f(R,1,1),t.uniform2f(b,0,0),t.uniform1i(T,0),t.uniform1i(U,1),t.uniform2f(D,0,1),t.uniform1f(C,0),t.uniform1f(B,0);let x=null;s!=null&&s.complete?H(s):s&&(s.onload=()=>{H(s)});function G(){t.viewport(0,0,m,h),t.useProgram(_),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,i),x!==null&&(t.activeTexture(t.TEXTURE2),t.bindTexture(t.TEXTURE_2D,x),t.uniform1i(W,2)),t.bindFramebuffer(t.FRAMEBUFFER,null),t.drawArrays(t.TRIANGLE_STRIP,0,4)}function H(F){x=ce(t,t.RGBA8,F.naturalWidth,F.naturalHeight,t.LINEAR,t.LINEAR),t.texSubImage2D(t.TEXTURE_2D,0,0,0,F.naturalWidth,F.naturalHeight,t.RGBA,t.UNSIGNED_BYTE,F);let J=0,Z=0,Y=F.naturalWidth,ee=F.naturalHeight;Y/ee<u?(ee=Y/u,Z=(F.naturalHeight-ee)/2):(Y=ee*u,J=(F.naturalWidth-Y)/2);const X=Y/F.naturalWidth,be=ee/F.naturalHeight;J/=F.naturalWidth,Z/=F.naturalHeight,t.uniform2f(R,X,be),t.uniform2f(b,J,Z)}function j(F){t.useProgram(_),t.uniform2f(D,F[0],F[1])}function A(F){t.useProgram(_),t.uniform1f(C,F)}function L(F){t.useProgram(_),t.uniform1f(B,F==="screen"?0:1)}function re(){t.deleteTexture(x),t.deleteProgram(_),t.deleteShader(E),t.deleteShader(w)}return{render:G,updateCoverage:j,updateLightWrapping:A,updateBlendMode:L,cleanUp:re}}function Tt(t,r,e,i,s,c,f,p){const l=ne`#version 300 es
|
|
122
|
+
|
|
123
|
+
precision highp float;
|
|
124
|
+
|
|
125
|
+
uniform sampler2D u_inputFrame;
|
|
126
|
+
uniform sampler2D u_segmentationMask;
|
|
127
|
+
uniform vec2 u_texelSize;
|
|
128
|
+
uniform float u_step;
|
|
129
|
+
uniform float u_radius;
|
|
130
|
+
uniform float u_offset;
|
|
131
|
+
uniform float u_sigmaTexel;
|
|
132
|
+
uniform float u_sigmaColor;
|
|
133
|
+
|
|
134
|
+
in vec2 v_texCoord;
|
|
135
|
+
|
|
136
|
+
out vec4 outColor;
|
|
137
|
+
|
|
138
|
+
float gaussian(float x, float sigma) {
|
|
139
|
+
float coeff = -0.5 / (sigma * sigma * 4.0 + 1.0e-6);
|
|
140
|
+
return exp((x * x) * coeff);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
void main() {
|
|
144
|
+
vec2 centerCoord = v_texCoord;
|
|
145
|
+
vec3 centerColor = texture(u_inputFrame, centerCoord).rgb;
|
|
146
|
+
float newVal = 0.0;
|
|
147
|
+
|
|
148
|
+
float spaceWeight = 0.0;
|
|
149
|
+
float colorWeight = 0.0;
|
|
150
|
+
float totalWeight = 0.0;
|
|
151
|
+
|
|
152
|
+
// Subsample kernel space.
|
|
153
|
+
for (float i = -u_radius + u_offset; i <= u_radius; i += u_step) {
|
|
154
|
+
for (float j = -u_radius + u_offset; j <= u_radius; j += u_step) {
|
|
155
|
+
vec2 shift = vec2(j, i) * u_texelSize;
|
|
156
|
+
vec2 coord = vec2(centerCoord + shift);
|
|
157
|
+
vec3 frameColor = texture(u_inputFrame, coord).rgb;
|
|
158
|
+
float outVal = texture(u_segmentationMask, coord).a;
|
|
159
|
+
|
|
160
|
+
spaceWeight = gaussian(distance(centerCoord, coord), u_sigmaTexel);
|
|
161
|
+
colorWeight = gaussian(distance(centerColor, frameColor), u_sigmaColor);
|
|
162
|
+
totalWeight += spaceWeight * colorWeight;
|
|
163
|
+
|
|
164
|
+
newVal += spaceWeight * colorWeight * outVal;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
newVal /= totalWeight;
|
|
168
|
+
|
|
169
|
+
outColor = vec4(vec3(0.0), newVal);
|
|
170
|
+
}
|
|
171
|
+
`,[m,h]=ve[c.inputResolution],{width:u,height:w}=p,E=1/u,_=1/w,R=ie(t,t.FRAGMENT_SHADER,l),b=le(t,r,R,e,i),T=t.getUniformLocation(b,"u_inputFrame"),U=t.getUniformLocation(b,"u_segmentationMask"),W=t.getUniformLocation(b,"u_texelSize"),D=t.getUniformLocation(b,"u_step"),C=t.getUniformLocation(b,"u_radius"),B=t.getUniformLocation(b,"u_offset"),x=t.getUniformLocation(b,"u_sigmaTexel"),G=t.getUniformLocation(b,"u_sigmaColor"),H=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,H),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,f,0),t.useProgram(b),t.uniform1i(T,0),t.uniform1i(U,1),t.uniform2f(W,E,_),A(0),L(0);function j(){t.viewport(0,0,u,w),t.useProgram(b),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,s),t.bindFramebuffer(t.FRAMEBUFFER,H),t.drawArrays(t.TRIANGLE_STRIP,0,4)}function A(F){F*=Math.max(u/m,w/h);const J=.66,Y=Math.max(1,Math.sqrt(F)*J),ee=F,V=Y>1?Y*.5:0,X=Math.max(E,_)*F;t.useProgram(b),t.uniform1f(D,Y),t.uniform1f(C,ee),t.uniform1f(B,V),t.uniform1f(x,X)}function L(F){t.useProgram(b),t.uniform1f(G,F)}function re(){t.deleteFramebuffer(H),t.deleteProgram(b),t.deleteShader(R)}return{render:j,updateSigmaSpace:A,updateSigmaColor:L,cleanUp:re}}function xt(t,r,e,i,s,c,f){const p=ne`#version 300 es
|
|
172
|
+
|
|
173
|
+
precision highp float;
|
|
174
|
+
|
|
175
|
+
uniform sampler2D u_inputSegmentation;
|
|
176
|
+
|
|
177
|
+
in vec2 v_texCoord;
|
|
178
|
+
|
|
179
|
+
out vec4 outColor;
|
|
180
|
+
|
|
181
|
+
void main() {
|
|
182
|
+
float segmentation = texture(u_inputSegmentation, v_texCoord).r;
|
|
183
|
+
outColor = vec4(vec3(0.0), segmentation);
|
|
184
|
+
}
|
|
185
|
+
`,l=c._getOutputMemoryOffset()/4,[m,h]=ve[s.inputResolution],u=ie(t,t.FRAGMENT_SHADER,p),w=le(t,r,u,e,i),E=t.getUniformLocation(w,"u_inputSegmentation"),_=ce(t,t.R32F,m,h),R=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,R),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,f,0),t.useProgram(w),t.uniform1i(E,1);function b(){t.viewport(0,0,m,h),t.useProgram(w),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,_),t.texSubImage2D(t.TEXTURE_2D,0,0,0,m,h,t.RED,t.FLOAT,c.HEAPF32,l),t.bindFramebuffer(t.FRAMEBUFFER,R),t.drawArrays(t.TRIANGLE_STRIP,0,4)}function T(){t.deleteFramebuffer(R),t.deleteTexture(_),t.deleteProgram(w),t.deleteShader(u)}return{render:b,cleanUp:T}}function Ct(t,r,e,i,s,c,f){const p=ne`#version 300 es
|
|
186
|
+
|
|
187
|
+
precision highp float;
|
|
188
|
+
|
|
189
|
+
uniform sampler2D u_inputFrame;
|
|
190
|
+
|
|
191
|
+
in vec2 v_texCoord;
|
|
192
|
+
|
|
193
|
+
out vec4 outColor;
|
|
194
|
+
|
|
195
|
+
void main() {
|
|
196
|
+
outColor = texture(u_inputFrame, v_texCoord);
|
|
197
|
+
}
|
|
198
|
+
`,l=f._getInputMemoryOffset()/4,[m,h]=ve[c.inputResolution],u=m*h,w=ie(r,r.FRAGMENT_SHADER,p),E=le(r,e,w,i,s),_=r.getUniformLocation(E,"u_inputFrame"),R=ce(r,r.RGBA8,m,h),b=r.createFramebuffer();r.bindFramebuffer(r.FRAMEBUFFER,b),r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0,r.TEXTURE_2D,R,0);const T=new Uint8Array(u*4);r.useProgram(E),r.uniform1i(_,0);async function U(){r.viewport(0,0,m,h),r.useProgram(E),r.bindFramebuffer(r.FRAMEBUFFER,b),r.drawArrays(r.TRIANGLE_STRIP,0,4);const D=yt(t,r,0,0,m,h,r.RGBA,r.UNSIGNED_BYTE,T);c.deferInputResizing||await D;for(let C=0;C<u;C++){const B=l+C*3,x=C*4;f.HEAPF32[B]=T[x]/255,f.HEAPF32[B+1]=T[x+1]/255,f.HEAPF32[B+2]=T[x+2]/255}}function W(){r.deleteFramebuffer(b),r.deleteTexture(R),r.deleteProgram(E),r.deleteShader(w)}return{render:U,cleanUp:W}}function Bt(t,r,e,i,s,c,f){const p=ne`#version 300 es
|
|
199
|
+
|
|
200
|
+
precision highp float;
|
|
201
|
+
|
|
202
|
+
uniform sampler2D u_inputSegmentation;
|
|
203
|
+
|
|
204
|
+
in vec2 v_texCoord;
|
|
205
|
+
|
|
206
|
+
out vec4 outColor;
|
|
207
|
+
|
|
208
|
+
void main() {
|
|
209
|
+
vec2 segmentation = texture(u_inputSegmentation, v_texCoord).rg;
|
|
210
|
+
float shift = max(segmentation.r, segmentation.g);
|
|
211
|
+
float backgroundExp = exp(segmentation.r - shift);
|
|
212
|
+
float personExp = exp(segmentation.g - shift);
|
|
213
|
+
outColor = vec4(vec3(0.0), personExp / (backgroundExp + personExp));
|
|
214
|
+
}
|
|
215
|
+
`,l=c._getOutputMemoryOffset()/4,[m,h]=ve[s.inputResolution],u=ie(t,t.FRAGMENT_SHADER,p),w=le(t,r,u,e,i),E=t.getUniformLocation(w,"u_inputSegmentation"),_=ce(t,t.RG32F,m,h),R=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,R),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,f,0),t.useProgram(w),t.uniform1i(E,1);function b(){t.viewport(0,0,m,h),t.useProgram(w),t.activeTexture(t.TEXTURE1),t.bindTexture(t.TEXTURE_2D,_),t.texSubImage2D(t.TEXTURE_2D,0,0,0,m,h,t.RG,t.FLOAT,c.HEAPF32,l),t.bindFramebuffer(t.FRAMEBUFFER,R),t.drawArrays(t.TRIANGLE_STRIP,0,4)}function T(){t.deleteFramebuffer(R),t.deleteTexture(_),t.deleteProgram(w),t.deleteShader(u)}return{render:b,cleanUp:T}}function ht(t,r,e,i,s,c){const f=ne`#version 300 es
|
|
216
|
+
|
|
217
|
+
in vec2 a_position;
|
|
218
|
+
in vec2 a_texCoord;
|
|
219
|
+
|
|
220
|
+
out vec2 v_texCoord;
|
|
221
|
+
|
|
222
|
+
void main() {
|
|
223
|
+
gl_Position = vec4(a_position, 0.0, 1.0);
|
|
224
|
+
v_texCoord = a_texCoord;
|
|
225
|
+
}
|
|
226
|
+
`,{width:p,height:l}=t,[m,h]=ve[e.inputResolution],u=i.getContext("webgl2"),w=ie(u,u.VERTEX_SHADER,f),E=u.createVertexArray();u.bindVertexArray(E);const _=u.createBuffer();u.bindBuffer(u.ARRAY_BUFFER,_),u.bufferData(u.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,1,1]),u.STATIC_DRAW);const R=u.createBuffer();u.bindBuffer(u.ARRAY_BUFFER,R),u.bufferData(u.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,1,1]),u.STATIC_DRAW);const b=u.createTexture();u.bindTexture(u.TEXTURE_2D,b),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_S,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_WRAP_T,u.CLAMP_TO_EDGE),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MIN_FILTER,u.NEAREST),u.texParameteri(u.TEXTURE_2D,u.TEXTURE_MAG_FILTER,u.NEAREST);const T=ce(u,u.RGBA8,m,h),U=ce(u,u.RGBA8,p,l),W=Ct(c,u,w,_,R,e,s),D=e.model==="meet"?Bt(u,w,_,R,e,s,T):xt(u,w,_,R,e,s,T),C=Tt(u,w,_,R,T,e,U,i),B=r.type==="blur"?Mt(u,w,_,R,U,i,r):Ft(u,_,R,U,r.backgroundImage,i);async function x(){u.activeTexture(u.TEXTURE0),u.bindTexture(u.TEXTURE_2D,b),u.texImage2D(u.TEXTURE_2D,0,u.RGBA,u.RGBA,u.UNSIGNED_BYTE,t.htmlElement),u.bindVertexArray(E),await W.render(),s._runInference(),D.render(),C.render(),B.render()}function G(j){if(C.updateSigmaSpace(j.jointBilateralFilter.sigmaSpace),C.updateSigmaColor(j.jointBilateralFilter.sigmaColor),r.type==="image"){const A=B;A.updateCoverage(j.coverage),A.updateLightWrapping(j.lightWrapping),A.updateBlendMode(j.blendMode)}else if(r.type==="blur")B.updateCoverage(j.coverage);else{const A=B;A.updateCoverage([0,.9999]),A.updateLightWrapping(0)}}function H(){B.cleanUp(),C.cleanUp(),D.cleanUp(),W.cleanUp(),u.deleteTexture(U),u.deleteTexture(T),u.deleteTexture(b),u.deleteBuffer(R),u.deleteBuffer(_),u.deleteVertexArray(E),u.deleteShader(w)}return{render:x,updatePostProcessingConfig:G,cleanUp:H}}const Pt={"Amazon Silk":"amazon_silk","Android Browser":"android",Bada:"bada",BlackBerry:"blackberry",Chrome:"chrome",Chromium:"chromium",Electron:"electron",Epiphany:"epiphany",Firefox:"firefox",Focus:"focus",Generic:"generic","Google Search":"google_search",Googlebot:"googlebot","Internet Explorer":"ie","K-Meleon":"k_meleon",Maxthon:"maxthon","Microsoft Edge":"edge","MZ Browser":"mz","NAVER Whale Browser":"naver",Opera:"opera","Opera Coast":"opera_coast",PhantomJS:"phantomjs",Puffin:"puffin",QupZilla:"qupzilla",QQ:"qq",QQLite:"qqlite",Safari:"safari",Sailfish:"sailfish","Samsung Internet for Android":"samsung_internet",SeaMonkey:"seamonkey",Sleipnir:"sleipnir",Swing:"swing",Tizen:"tizen","UC Browser":"uc",Vivaldi:"vivaldi","WebOS Browser":"webos",WeChat:"wechat","Yandex Browser":"yandex",Roku:"roku"},_t={amazon_silk:"Amazon Silk",android:"Android Browser",bada:"Bada",blackberry:"BlackBerry",chrome:"Chrome",chromium:"Chromium",electron:"Electron",epiphany:"Epiphany",firefox:"Firefox",focus:"Focus",generic:"Generic",googlebot:"Googlebot",google_search:"Google Search",ie:"Internet Explorer",k_meleon:"K-Meleon",maxthon:"Maxthon",edge:"Microsoft Edge",mz:"MZ Browser",naver:"NAVER Whale Browser",opera:"Opera",opera_coast:"Opera Coast",phantomjs:"PhantomJS",puffin:"Puffin",qupzilla:"QupZilla",qq:"QQ Browser",qqlite:"QQ Browser Lite",safari:"Safari",sailfish:"Sailfish",samsung_internet:"Samsung Internet for Android",seamonkey:"SeaMonkey",sleipnir:"Sleipnir",swing:"Swing",tizen:"Tizen",uc:"UC Browser",vivaldi:"Vivaldi",webos:"WebOS Browser",wechat:"WeChat",yandex:"Yandex Browser"},N={tablet:"tablet",mobile:"mobile",desktop:"desktop",tv:"tv"},q={WindowsPhone:"Windows Phone",Windows:"Windows",MacOS:"macOS",iOS:"iOS",Android:"Android",WebOS:"WebOS",BlackBerry:"BlackBerry",Bada:"Bada",Tizen:"Tizen",Linux:"Linux",ChromeOS:"Chrome OS",PlayStation4:"PlayStation 4",Roku:"Roku"},ue={EdgeHTML:"EdgeHTML",Blink:"Blink",Trident:"Trident",Presto:"Presto",Gecko:"Gecko",WebKit:"WebKit"};class a{static getFirstMatch(r,e){const i=e.match(r);return i&&i.length>0&&i[1]||""}static getSecondMatch(r,e){const i=e.match(r);return i&&i.length>1&&i[2]||""}static matchAndReturnConst(r,e,i){if(r.test(e))return i}static getWindowsVersionName(r){switch(r){case"NT":return"NT";case"XP":return"XP";case"NT 5.0":return"2000";case"NT 5.1":return"XP";case"NT 5.2":return"2003";case"NT 6.0":return"Vista";case"NT 6.1":return"7";case"NT 6.2":return"8";case"NT 6.3":return"8.1";case"NT 10.0":return"10";default:return}}static getMacOSVersionName(r){const e=r.split(".").splice(0,2).map(i=>parseInt(i,10)||0);if(e.push(0),e[0]===10)switch(e[1]){case 5:return"Leopard";case 6:return"Snow Leopard";case 7:return"Lion";case 8:return"Mountain Lion";case 9:return"Mavericks";case 10:return"Yosemite";case 11:return"El Capitan";case 12:return"Sierra";case 13:return"High Sierra";case 14:return"Mojave";case 15:return"Catalina";default:return}}static getAndroidVersionName(r){const e=r.split(".").splice(0,2).map(i=>parseInt(i,10)||0);if(e.push(0),!(e[0]===1&&e[1]<5)){if(e[0]===1&&e[1]<6)return"Cupcake";if(e[0]===1&&e[1]>=6)return"Donut";if(e[0]===2&&e[1]<2)return"Eclair";if(e[0]===2&&e[1]===2)return"Froyo";if(e[0]===2&&e[1]>2)return"Gingerbread";if(e[0]===3)return"Honeycomb";if(e[0]===4&&e[1]<1)return"Ice Cream Sandwich";if(e[0]===4&&e[1]<4)return"Jelly Bean";if(e[0]===4&&e[1]>=4)return"KitKat";if(e[0]===5)return"Lollipop";if(e[0]===6)return"Marshmallow";if(e[0]===7)return"Nougat";if(e[0]===8)return"Oreo";if(e[0]===9)return"Pie"}}static getVersionPrecision(r){return r.split(".").length}static compareVersions(r,e,i=!1){const s=a.getVersionPrecision(r),c=a.getVersionPrecision(e);let f=Math.max(s,c),p=0;const l=a.map([r,e],m=>{const h=f-a.getVersionPrecision(m),u=m+new Array(h+1).join(".0");return a.map(u.split("."),w=>new Array(20-w.length).join("0")+w).reverse()});for(i&&(p=f-Math.min(s,c)),f-=1;f>=p;){if(l[0][f]>l[1][f])return 1;if(l[0][f]===l[1][f]){if(f===p)return 0;f-=1}else if(l[0][f]<l[1][f])return-1}}static map(r,e){const i=[];let s;if(Array.prototype.map)return Array.prototype.map.call(r,e);for(s=0;s<r.length;s+=1)i.push(e(r[s]));return i}static find(r,e){let i,s;if(Array.prototype.find)return Array.prototype.find.call(r,e);for(i=0,s=r.length;i<s;i+=1){const c=r[i];if(e(c,i))return c}}static assign(r,...e){const i=r;let s,c;if(Object.assign)return Object.assign(r,...e);for(s=0,c=e.length;s<c;s+=1){const f=e[s];typeof f=="object"&&f!==null&&Object.keys(f).forEach(l=>{i[l]=f[l]})}return r}static getBrowserAlias(r){return Pt[r]}static getBrowserTypeByAlias(r){return _t[r]||""}}const k=/version\/(\d+(\.?_?\d+)+)/i,kt=[{test:[/googlebot/i],describe(t){const r={name:"Googlebot"},e=a.getFirstMatch(/googlebot\/(\d+(\.\d+))/i,t)||a.getFirstMatch(k,t);return e&&(r.version=e),r}},{test:[/opera/i],describe(t){const r={name:"Opera"},e=a.getFirstMatch(k,t)||a.getFirstMatch(/(?:opera)[\s/](\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/opr\/|opios/i],describe(t){const r={name:"Opera"},e=a.getFirstMatch(/(?:opr|opios)[\s/](\S+)/i,t)||a.getFirstMatch(k,t);return e&&(r.version=e),r}},{test:[/SamsungBrowser/i],describe(t){const r={name:"Samsung Internet for Android"},e=a.getFirstMatch(k,t)||a.getFirstMatch(/(?:SamsungBrowser)[\s/](\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/Whale/i],describe(t){const r={name:"NAVER Whale Browser"},e=a.getFirstMatch(k,t)||a.getFirstMatch(/(?:whale)[\s/](\d+(?:\.\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/MZBrowser/i],describe(t){const r={name:"MZ Browser"},e=a.getFirstMatch(/(?:MZBrowser)[\s/](\d+(?:\.\d+)+)/i,t)||a.getFirstMatch(k,t);return e&&(r.version=e),r}},{test:[/focus/i],describe(t){const r={name:"Focus"},e=a.getFirstMatch(/(?:focus)[\s/](\d+(?:\.\d+)+)/i,t)||a.getFirstMatch(k,t);return e&&(r.version=e),r}},{test:[/swing/i],describe(t){const r={name:"Swing"},e=a.getFirstMatch(/(?:swing)[\s/](\d+(?:\.\d+)+)/i,t)||a.getFirstMatch(k,t);return e&&(r.version=e),r}},{test:[/coast/i],describe(t){const r={name:"Opera Coast"},e=a.getFirstMatch(k,t)||a.getFirstMatch(/(?:coast)[\s/](\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/opt\/\d+(?:.?_?\d+)+/i],describe(t){const r={name:"Opera Touch"},e=a.getFirstMatch(/(?:opt)[\s/](\d+(\.?_?\d+)+)/i,t)||a.getFirstMatch(k,t);return e&&(r.version=e),r}},{test:[/yabrowser/i],describe(t){const r={name:"Yandex Browser"},e=a.getFirstMatch(/(?:yabrowser)[\s/](\d+(\.?_?\d+)+)/i,t)||a.getFirstMatch(k,t);return e&&(r.version=e),r}},{test:[/ucbrowser/i],describe(t){const r={name:"UC Browser"},e=a.getFirstMatch(k,t)||a.getFirstMatch(/(?:ucbrowser)[\s/](\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/Maxthon|mxios/i],describe(t){const r={name:"Maxthon"},e=a.getFirstMatch(k,t)||a.getFirstMatch(/(?:Maxthon|mxios)[\s/](\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/epiphany/i],describe(t){const r={name:"Epiphany"},e=a.getFirstMatch(k,t)||a.getFirstMatch(/(?:epiphany)[\s/](\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/puffin/i],describe(t){const r={name:"Puffin"},e=a.getFirstMatch(k,t)||a.getFirstMatch(/(?:puffin)[\s/](\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/sleipnir/i],describe(t){const r={name:"Sleipnir"},e=a.getFirstMatch(k,t)||a.getFirstMatch(/(?:sleipnir)[\s/](\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/k-meleon/i],describe(t){const r={name:"K-Meleon"},e=a.getFirstMatch(k,t)||a.getFirstMatch(/(?:k-meleon)[\s/](\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/micromessenger/i],describe(t){const r={name:"WeChat"},e=a.getFirstMatch(/(?:micromessenger)[\s/](\d+(\.?_?\d+)+)/i,t)||a.getFirstMatch(k,t);return e&&(r.version=e),r}},{test:[/qqbrowser/i],describe(t){const r={name:/qqbrowserlite/i.test(t)?"QQ Browser Lite":"QQ Browser"},e=a.getFirstMatch(/(?:qqbrowserlite|qqbrowser)[/](\d+(\.?_?\d+)+)/i,t)||a.getFirstMatch(k,t);return e&&(r.version=e),r}},{test:[/msie|trident/i],describe(t){const r={name:"Internet Explorer"},e=a.getFirstMatch(/(?:msie |rv:)(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/\sedg\//i],describe(t){const r={name:"Microsoft Edge"},e=a.getFirstMatch(/\sedg\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/edg([ea]|ios)/i],describe(t){const r={name:"Microsoft Edge"},e=a.getSecondMatch(/edg([ea]|ios)\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/vivaldi/i],describe(t){const r={name:"Vivaldi"},e=a.getFirstMatch(/vivaldi\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/seamonkey/i],describe(t){const r={name:"SeaMonkey"},e=a.getFirstMatch(/seamonkey\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/sailfish/i],describe(t){const r={name:"Sailfish"},e=a.getFirstMatch(/sailfish\s?browser\/(\d+(\.\d+)?)/i,t);return e&&(r.version=e),r}},{test:[/silk/i],describe(t){const r={name:"Amazon Silk"},e=a.getFirstMatch(/silk\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/phantom/i],describe(t){const r={name:"PhantomJS"},e=a.getFirstMatch(/phantomjs\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/slimerjs/i],describe(t){const r={name:"SlimerJS"},e=a.getFirstMatch(/slimerjs\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/blackberry|\bbb\d+/i,/rim\stablet/i],describe(t){const r={name:"BlackBerry"},e=a.getFirstMatch(k,t)||a.getFirstMatch(/blackberry[\d]+\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/(web|hpw)[o0]s/i],describe(t){const r={name:"WebOS Browser"},e=a.getFirstMatch(k,t)||a.getFirstMatch(/w(?:eb)?[o0]sbrowser\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/bada/i],describe(t){const r={name:"Bada"},e=a.getFirstMatch(/dolfin\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/tizen/i],describe(t){const r={name:"Tizen"},e=a.getFirstMatch(/(?:tizen\s?)?browser\/(\d+(\.?_?\d+)+)/i,t)||a.getFirstMatch(k,t);return e&&(r.version=e),r}},{test:[/qupzilla/i],describe(t){const r={name:"QupZilla"},e=a.getFirstMatch(/(?:qupzilla)[\s/](\d+(\.?_?\d+)+)/i,t)||a.getFirstMatch(k,t);return e&&(r.version=e),r}},{test:[/firefox|iceweasel|fxios/i],describe(t){const r={name:"Firefox"},e=a.getFirstMatch(/(?:firefox|iceweasel|fxios)[\s/](\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/electron/i],describe(t){const r={name:"Electron"},e=a.getFirstMatch(/(?:electron)\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/MiuiBrowser/i],describe(t){const r={name:"Miui"},e=a.getFirstMatch(/(?:MiuiBrowser)[\s/](\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/chromium/i],describe(t){const r={name:"Chromium"},e=a.getFirstMatch(/(?:chromium)[\s/](\d+(\.?_?\d+)+)/i,t)||a.getFirstMatch(k,t);return e&&(r.version=e),r}},{test:[/chrome|crios|crmo/i],describe(t){const r={name:"Chrome"},e=a.getFirstMatch(/(?:chrome|crios|crmo)\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/GSA/i],describe(t){const r={name:"Google Search"},e=a.getFirstMatch(/(?:GSA)\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test(t){const r=!t.test(/like android/i),e=t.test(/android/i);return r&&e},describe(t){const r={name:"Android Browser"},e=a.getFirstMatch(k,t);return e&&(r.version=e),r}},{test:[/playstation 4/i],describe(t){const r={name:"PlayStation 4"},e=a.getFirstMatch(k,t);return e&&(r.version=e),r}},{test:[/safari|applewebkit/i],describe(t){const r={name:"Safari"},e=a.getFirstMatch(k,t);return e&&(r.version=e),r}},{test:[/.*/i],describe(t){const r=/^(.*)\/(.*) /,e=/^(.*)\/(.*)[ \t]\((.*)/,s=t.search("\\(")!==-1?e:r;return{name:a.getFirstMatch(s,t),version:a.getSecondMatch(s,t)}}}];var Ot=[{test:[/Roku\/DVP/],describe(t){const r=a.getFirstMatch(/Roku\/DVP-(\d+\.\d+)/i,t);return{name:q.Roku,version:r}}},{test:[/windows phone/i],describe(t){const r=a.getFirstMatch(/windows phone (?:os)?\s?(\d+(\.\d+)*)/i,t);return{name:q.WindowsPhone,version:r}}},{test:[/windows /i],describe(t){const r=a.getFirstMatch(/Windows ((NT|XP)( \d\d?.\d)?)/i,t),e=a.getWindowsVersionName(r);return{name:q.Windows,version:r,versionName:e}}},{test:[/Macintosh(.*?) FxiOS(.*?)\//],describe(t){const r={name:q.iOS},e=a.getSecondMatch(/(Version\/)(\d[\d.]+)/,t);return e&&(r.version=e),r}},{test:[/macintosh/i],describe(t){const r=a.getFirstMatch(/mac os x (\d+(\.?_?\d+)+)/i,t).replace(/[_\s]/g,"."),e=a.getMacOSVersionName(r),i={name:q.MacOS,version:r};return e&&(i.versionName=e),i}},{test:[/(ipod|iphone|ipad)/i],describe(t){const r=a.getFirstMatch(/os (\d+([_\s]\d+)*) like mac os x/i,t).replace(/[_\s]/g,".");return{name:q.iOS,version:r}}},{test(t){const r=!t.test(/like android/i),e=t.test(/android/i);return r&&e},describe(t){const r=a.getFirstMatch(/android[\s/-](\d+(\.\d+)*)/i,t),e=a.getAndroidVersionName(r),i={name:q.Android,version:r};return e&&(i.versionName=e),i}},{test:[/(web|hpw)[o0]s/i],describe(t){const r=a.getFirstMatch(/(?:web|hpw)[o0]s\/(\d+(\.\d+)*)/i,t),e={name:q.WebOS};return r&&r.length&&(e.version=r),e}},{test:[/blackberry|\bbb\d+/i,/rim\stablet/i],describe(t){const r=a.getFirstMatch(/rim\stablet\sos\s(\d+(\.\d+)*)/i,t)||a.getFirstMatch(/blackberry\d+\/(\d+([_\s]\d+)*)/i,t)||a.getFirstMatch(/\bbb(\d+)/i,t);return{name:q.BlackBerry,version:r}}},{test:[/bada/i],describe(t){const r=a.getFirstMatch(/bada\/(\d+(\.\d+)*)/i,t);return{name:q.Bada,version:r}}},{test:[/tizen/i],describe(t){const r=a.getFirstMatch(/tizen[/\s](\d+(\.\d+)*)/i,t);return{name:q.Tizen,version:r}}},{test:[/linux/i],describe(){return{name:q.Linux}}},{test:[/CrOS/],describe(){return{name:q.ChromeOS}}},{test:[/PlayStation 4/],describe(t){const r=a.getFirstMatch(/PlayStation 4[/\s](\d+(\.\d+)*)/i,t);return{name:q.PlayStation4,version:r}}}],Ut=[{test:[/googlebot/i],describe(){return{type:"bot",vendor:"Google"}}},{test:[/huawei/i],describe(t){const r=a.getFirstMatch(/(can-l01)/i,t)&&"Nova",e={type:N.mobile,vendor:"Huawei"};return r&&(e.model=r),e}},{test:[/nexus\s*(?:7|8|9|10).*/i],describe(){return{type:N.tablet,vendor:"Nexus"}}},{test:[/ipad/i],describe(){return{type:N.tablet,vendor:"Apple",model:"iPad"}}},{test:[/Macintosh(.*?) FxiOS(.*?)\//],describe(){return{type:N.tablet,vendor:"Apple",model:"iPad"}}},{test:[/kftt build/i],describe(){return{type:N.tablet,vendor:"Amazon",model:"Kindle Fire HD 7"}}},{test:[/silk/i],describe(){return{type:N.tablet,vendor:"Amazon"}}},{test:[/tablet(?! pc)/i],describe(){return{type:N.tablet}}},{test(t){const r=t.test(/ipod|iphone/i),e=t.test(/like (ipod|iphone)/i);return r&&!e},describe(t){const r=a.getFirstMatch(/(ipod|iphone)/i,t);return{type:N.mobile,vendor:"Apple",model:r}}},{test:[/nexus\s*[0-6].*/i,/galaxy nexus/i],describe(){return{type:N.mobile,vendor:"Nexus"}}},{test:[/[^-]mobi/i],describe(){return{type:N.mobile}}},{test(t){return t.getBrowserName(!0)==="blackberry"},describe(){return{type:N.mobile,vendor:"BlackBerry"}}},{test(t){return t.getBrowserName(!0)==="bada"},describe(){return{type:N.mobile}}},{test(t){return t.getBrowserName()==="windows phone"},describe(){return{type:N.mobile,vendor:"Microsoft"}}},{test(t){const r=Number(String(t.getOSVersion()).split(".")[0]);return t.getOSName(!0)==="android"&&r>=3},describe(){return{type:N.tablet}}},{test(t){return t.getOSName(!0)==="android"},describe(){return{type:N.mobile}}},{test(t){return t.getOSName(!0)==="macos"},describe(){return{type:N.desktop,vendor:"Apple"}}},{test(t){return t.getOSName(!0)==="windows"},describe(){return{type:N.desktop}}},{test(t){return t.getOSName(!0)==="linux"},describe(){return{type:N.desktop}}},{test(t){return t.getOSName(!0)==="playstation 4"},describe(){return{type:N.tv}}},{test(t){return t.getOSName(!0)==="roku"},describe(){return{type:N.tv}}}],It=[{test(t){return t.getBrowserName(!0)==="microsoft edge"},describe(t){if(/\sedg\//i.test(t))return{name:ue.Blink};const e=a.getFirstMatch(/edge\/(\d+(\.?_?\d+)+)/i,t);return{name:ue.EdgeHTML,version:e}}},{test:[/trident/i],describe(t){const r={name:ue.Trident},e=a.getFirstMatch(/trident\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test(t){return t.test(/presto/i)},describe(t){const r={name:ue.Presto},e=a.getFirstMatch(/presto\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test(t){const r=t.test(/gecko/i),e=t.test(/like gecko/i);return r&&!e},describe(t){const r={name:ue.Gecko},e=a.getFirstMatch(/gecko\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}},{test:[/(apple)?webkit\/537\.36/i],describe(){return{name:ue.Blink}}},{test:[/(apple)?webkit/i],describe(t){const r={name:ue.WebKit},e=a.getFirstMatch(/webkit\/(\d+(\.?_?\d+)+)/i,t);return e&&(r.version=e),r}}];class mt{constructor(r,e=!1){if(r==null||r==="")throw new Error("UserAgent parameter can't be empty");this._ua=r,this.parsedResult={},e!==!0&&this.parse()}getUA(){return this._ua}test(r){return r.test(this._ua)}parseBrowser(){this.parsedResult.browser={};const r=a.find(kt,e=>{if(typeof e.test=="function")return e.test(this);if(e.test instanceof Array)return e.test.some(i=>this.test(i));throw new Error("Browser's test function is not valid")});return r&&(this.parsedResult.browser=r.describe(this.getUA())),this.parsedResult.browser}getBrowser(){return this.parsedResult.browser?this.parsedResult.browser:this.parseBrowser()}getBrowserName(r){return r?String(this.getBrowser().name).toLowerCase()||"":this.getBrowser().name||""}getBrowserVersion(){return this.getBrowser().version}getOS(){return this.parsedResult.os?this.parsedResult.os:this.parseOS()}parseOS(){this.parsedResult.os={};const r=a.find(Ot,e=>{if(typeof e.test=="function")return e.test(this);if(e.test instanceof Array)return e.test.some(i=>this.test(i));throw new Error("Browser's test function is not valid")});return r&&(this.parsedResult.os=r.describe(this.getUA())),this.parsedResult.os}getOSName(r){const{name:e}=this.getOS();return r?String(e).toLowerCase()||"":e||""}getOSVersion(){return this.getOS().version}getPlatform(){return this.parsedResult.platform?this.parsedResult.platform:this.parsePlatform()}getPlatformType(r=!1){const{type:e}=this.getPlatform();return r?String(e).toLowerCase()||"":e||""}parsePlatform(){this.parsedResult.platform={};const r=a.find(Ut,e=>{if(typeof e.test=="function")return e.test(this);if(e.test instanceof Array)return e.test.some(i=>this.test(i));throw new Error("Browser's test function is not valid")});return r&&(this.parsedResult.platform=r.describe(this.getUA())),this.parsedResult.platform}getEngine(){return this.parsedResult.engine?this.parsedResult.engine:this.parseEngine()}getEngineName(r){return r?String(this.getEngine().name).toLowerCase()||"":this.getEngine().name||""}parseEngine(){this.parsedResult.engine={};const r=a.find(It,e=>{if(typeof e.test=="function")return e.test(this);if(e.test instanceof Array)return e.test.some(i=>this.test(i));throw new Error("Browser's test function is not valid")});return r&&(this.parsedResult.engine=r.describe(this.getUA())),this.parsedResult.engine}parse(){return this.parseBrowser(),this.parseOS(),this.parsePlatform(),this.parseEngine(),this}getResult(){return a.assign({},this.parsedResult)}satisfies(r){const e={};let i=0;const s={};let c=0;if(Object.keys(r).forEach(p=>{const l=r[p];typeof l=="string"?(s[p]=l,c+=1):typeof l=="object"&&(e[p]=l,i+=1)}),i>0){const p=Object.keys(e),l=a.find(p,h=>this.isOS(h));if(l){const h=this.satisfies(e[l]);if(h!==void 0)return h}const m=a.find(p,h=>this.isPlatform(h));if(m){const h=this.satisfies(e[m]);if(h!==void 0)return h}}if(c>0){const p=Object.keys(s),l=a.find(p,m=>this.isBrowser(m,!0));if(l!==void 0)return this.compareVersion(s[l])}}isBrowser(r,e=!1){const i=this.getBrowserName().toLowerCase();let s=r.toLowerCase();const c=a.getBrowserTypeByAlias(s);return e&&c&&(s=c.toLowerCase()),s===i}compareVersion(r){let e=[0],i=r,s=!1;const c=this.getBrowserVersion();if(typeof c=="string")return r[0]===">"||r[0]==="<"?(i=r.substr(1),r[1]==="="?(s=!0,i=r.substr(2)):e=[],r[0]===">"?e.push(1):e.push(-1)):r[0]==="="?i=r.substr(1):r[0]==="~"&&(s=!0,i=r.substr(1)),e.indexOf(a.compareVersions(c,i,s))>-1}isOS(r){return this.getOSName(!0)===String(r).toLowerCase()}isPlatform(r){return this.getPlatformType(!0)===String(r).toLowerCase()}isEngine(r){return this.getEngineName(!0)===String(r).toLowerCase()}is(r,e=!1){return this.isBrowser(r,e)||this.isOS(r)||this.isPlatform(r)}some(r=[]){return r.some(e=>this.is(e))}}/*!
|
|
227
|
+
* Bowser - a browser detector
|
|
228
|
+
* https://github.com/lancedikson/bowser
|
|
229
|
+
* MIT License | (c) Dustin Diaz 2012-2015
|
|
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;
|