Browse Source

fix(wasm-support): WebAssembly browser support. (#9410)

* fix(wasm-support): WebAssembly browser support.

* fix(wasm-support): WebAssembly browser support.

Co-authored-by: tudordan7 <tudor.pop@decagon.tech>
master
Tudor D. Pop 3 years ago
parent
commit
2ed2a8d41f
No account linked to committer's email address

+ 2
- 1
lang/main.json View File

@@ -362,7 +362,8 @@
362 362
         "image6" : "Forest ",
363 363
         "image7" : "Sunrise",
364 364
         "desktopShareError": "Could not create desktop share",
365
-        "desktopShare":"Desktop share"
365
+        "desktopShare":"Desktop share",
366
+        "webAssemblyWarning": "WebAssembly not supported"
366 367
     },
367 368
     "feedback": {
368 369
         "average": "Average",

+ 25
- 7
react/features/stream-effects/virtual-background/index.js View File

@@ -1,11 +1,11 @@
1 1
 // @flow
2 2
 
3
-import * as wasmCheck from 'wasm-check';
3
+import { showWarningNotification } from '../../notifications/actions';
4
+import logger from '../../virtual-background/logger';
4 5
 
5 6
 import JitsiStreamBackgroundEffect from './JitsiStreamBackgroundEffect';
6 7
 import createTFLiteModule from './vendor/tflite/tflite';
7 8
 import createTFLiteSIMDModule from './vendor/tflite/tflite-simd';
8
-
9 9
 const models = {
10 10
     model96: 'libs/segm_lite_v681.tflite',
11 11
     model144: 'libs/segm_full_v679.tflite'
@@ -28,18 +28,36 @@ const segmentationDimensions = {
28 28
  *
29 29
  * @param {Object} virtualBackground - The virtual object that contains the background image source and
30 30
  * the isVirtualBackground flag that indicates if virtual image is activated.
31
+ * @param {Function} dispatch - The Redux dispatch function.
31 32
  * @returns {Promise<JitsiStreamBackgroundEffect>}
32 33
  */
33
-export async function createVirtualBackgroundEffect(virtualBackground: Object) {
34
+export async function createVirtualBackgroundEffect(virtualBackground: Object, dispatch: Function) {
34 35
     if (!MediaStreamTrack.prototype.getSettings && !MediaStreamTrack.prototype.getConstraints) {
35 36
         throw new Error('JitsiStreamBackgroundEffect not supported!');
36 37
     }
37 38
     let tflite;
39
+    let wasmCheck;
40
+
41
+    // Checks if WebAssembly feature is supported or enabled by/in the browser.
42
+    // Conditional import of wasm-check package is done to prevent
43
+    // the browser from crashing when the user opens the app.
44
+
45
+    try {
46
+        wasmCheck = require('wasm-check');
47
+        if (wasmCheck?.feature?.simd) {
48
+            tflite = await createTFLiteSIMDModule();
49
+        } else {
50
+            tflite = await createTFLiteModule();
51
+        }
52
+    } catch (err) {
53
+        logger.error('Looks like WebAssembly is disabled or not supported on this browser');
54
+        dispatch(showWarningNotification({
55
+            titleKey: 'virtualBackground.webAssemblyWarning',
56
+            description: 'WebAssembly disabled or not supported by this browser'
57
+        }));
58
+
59
+        return;
38 60
 
39
-    if (wasmCheck.feature.simd) {
40
-        tflite = await createTFLiteSIMDModule();
41
-    } else {
42
-        tflite = await createTFLiteModule();
43 61
     }
44 62
 
45 63
     const modelBufferOffset = tflite._getModelBufferMemoryOffset();

+ 1
- 1
react/features/virtual-background/actions.js View File

@@ -22,7 +22,7 @@ export function toggleBackgroundEffect(options: Object, jitsiTrack: Object) {
22 22
         if (jitsiTrack) {
23 23
             try {
24 24
                 if (options.enabled) {
25
-                    await jitsiTrack.setEffect(await createVirtualBackgroundEffect(virtualBackground));
25
+                    await jitsiTrack.setEffect(await createVirtualBackgroundEffect(virtualBackground, dispatch));
26 26
                 } else {
27 27
                     await jitsiTrack.setEffect(undefined);
28 28
                     dispatch(backgroundEnabled(false));

Loading…
Cancel
Save