ソースを参照

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

Prevents downloading wasm module and module each time background is changed
master
Avram Tudor 3年前
コミット
f24e0f3622
コミッターのメールアドレスに関連付けられたアカウントが存在しません
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
     model144: 'libs/segm_full_v679.tflite'
12
     model144: 'libs/segm_full_v679.tflite'
13
 };
13
 };
14
 
14
 
15
+let tflite;
16
+let wasmCheck;
17
+let isWasmDisabled = false;
18
+
15
 const segmentationDimensions = {
19
 const segmentationDimensions = {
16
     model96: {
20
     model96: {
17
         height: 96,
21
         height: 96,
36
     if (!MediaStreamTrack.prototype.getSettings && !MediaStreamTrack.prototype.getConstraints) {
40
     if (!MediaStreamTrack.prototype.getSettings && !MediaStreamTrack.prototype.getConstraints) {
37
         throw new Error('JitsiStreamBackgroundEffect not supported!');
41
         throw new Error('JitsiStreamBackgroundEffect not supported!');
38
     }
42
     }
39
-    let tflite;
40
-    let wasmCheck;
41
 
43
 
42
     // Checks if WebAssembly feature is supported or enabled by/in the browser.
44
     // Checks if WebAssembly feature is supported or enabled by/in the browser.
43
     // Conditional import of wasm-check package is done to prevent
45
     // Conditional import of wasm-check package is done to prevent
44
     // the browser from crashing when the user opens the app.
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
     const modelBufferOffset = tflite._getModelBufferMemoryOffset();
78
     const modelBufferOffset = tflite._getModelBufferMemoryOffset();

読み込み中…
キャンセル
保存