瀏覽代碼

fix(virtual-backgrounds) cache wasm and model (#10190)

Prevents downloading wasm module and module each time background is changed
master
Avram Tudor 3 年之前
父節點
當前提交
f24e0f3622
No account linked to committer's email address
共有 1 個文件被更改,包括 31 次插入26 次删除
  1. 31
    26
      react/features/stream-effects/virtual-background/index.js

+ 31
- 26
react/features/stream-effects/virtual-background/index.js 查看文件

@@ -12,6 +12,10 @@ const models = {
12 12
     model144: 'libs/segm_full_v679.tflite'
13 13
 };
14 14
 
15
+let tflite;
16
+let wasmCheck;
17
+let isWasmDisabled = false;
18
+
15 19
 const segmentationDimensions = {
16 20
     model96: {
17 21
         height: 96,
@@ -36,38 +40,39 @@ export async function createVirtualBackgroundEffect(virtualBackground: Object, d
36 40
     if (!MediaStreamTrack.prototype.getSettings && !MediaStreamTrack.prototype.getConstraints) {
37 41
         throw new Error('JitsiStreamBackgroundEffect not supported!');
38 42
     }
39
-    let tflite;
40
-    let wasmCheck;
41 43
 
42 44
     // Checks if WebAssembly feature is supported or enabled by/in the browser.
43 45
     // Conditional import of wasm-check package is done to prevent
44 46
     // the browser from crashing when the user opens the app.
45 47
 
46
-    try {
47
-        wasmCheck = require('wasm-check');
48
-        const tfliteTimeout = 10000;
49
-
50
-        if (wasmCheck?.feature?.simd) {
51
-            tflite = await timeout(tfliteTimeout, createTFLiteSIMDModule());
52
-        } else {
53
-            tflite = await timeout(tfliteTimeout, createTFLiteModule());
54
-        }
55
-    } catch (err) {
56
-        if (err?.message === '408') {
57
-            logger.error('Failed to download tflite model!');
58
-            dispatch(showWarningNotification({
59
-                titleKey: 'virtualBackground.backgroundEffectError'
60
-            }));
61
-        } else {
62
-            logger.error('Looks like WebAssembly is disabled or not supported on this browser');
63
-            dispatch(showWarningNotification({
64
-                titleKey: 'virtualBackground.webAssemblyWarning',
65
-                description: 'WebAssembly disabled or not supported by this browser'
66
-            }));
48
+    if (!tflite && !isWasmDisabled) {
49
+        try {
50
+            wasmCheck = require('wasm-check');
51
+            const tfliteTimeout = 10000;
52
+
53
+            if (wasmCheck?.feature?.simd) {
54
+                tflite = await timeout(tfliteTimeout, createTFLiteSIMDModule());
55
+            } else {
56
+                tflite = await timeout(tfliteTimeout, createTFLiteModule());
57
+            }
58
+        } catch (err) {
59
+            isWasmDisabled = true;
60
+
61
+            if (err?.message === '408') {
62
+                logger.error('Failed to download tflite model!');
63
+                dispatch(showWarningNotification({
64
+                    titleKey: 'virtualBackground.backgroundEffectError'
65
+                }));
66
+            } else {
67
+                logger.error('Looks like WebAssembly is disabled or not supported on this browser');
68
+                dispatch(showWarningNotification({
69
+                    titleKey: 'virtualBackground.webAssemblyWarning',
70
+                    description: 'WebAssembly disabled or not supported by this browser'
71
+                }));
72
+            }
73
+
74
+            return;
67 75
         }
68
-
69
-        return;
70
-
71 76
     }
72 77
 
73 78
     const modelBufferOffset = tflite._getModelBufferMemoryOffset();

Loading…
取消
儲存