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 4 years ago
parent
commit
2ed2a8d41f
No account linked to committer's email address

+ 2
- 1
lang/main.json View File

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

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

1
 // @flow
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
 import JitsiStreamBackgroundEffect from './JitsiStreamBackgroundEffect';
6
 import JitsiStreamBackgroundEffect from './JitsiStreamBackgroundEffect';
6
 import createTFLiteModule from './vendor/tflite/tflite';
7
 import createTFLiteModule from './vendor/tflite/tflite';
7
 import createTFLiteSIMDModule from './vendor/tflite/tflite-simd';
8
 import createTFLiteSIMDModule from './vendor/tflite/tflite-simd';
8
-
9
 const models = {
9
 const models = {
10
     model96: 'libs/segm_lite_v681.tflite',
10
     model96: 'libs/segm_lite_v681.tflite',
11
     model144: 'libs/segm_full_v679.tflite'
11
     model144: 'libs/segm_full_v679.tflite'
28
  *
28
  *
29
  * @param {Object} virtualBackground - The virtual object that contains the background image source and
29
  * @param {Object} virtualBackground - The virtual object that contains the background image source and
30
  * the isVirtualBackground flag that indicates if virtual image is activated.
30
  * the isVirtualBackground flag that indicates if virtual image is activated.
31
+ * @param {Function} dispatch - The Redux dispatch function.
31
  * @returns {Promise<JitsiStreamBackgroundEffect>}
32
  * @returns {Promise<JitsiStreamBackgroundEffect>}
32
  */
33
  */
33
-export async function createVirtualBackgroundEffect(virtualBackground: Object) {
34
+export async function createVirtualBackgroundEffect(virtualBackground: Object, dispatch: Function) {
34
     if (!MediaStreamTrack.prototype.getSettings && !MediaStreamTrack.prototype.getConstraints) {
35
     if (!MediaStreamTrack.prototype.getSettings && !MediaStreamTrack.prototype.getConstraints) {
35
         throw new Error('JitsiStreamBackgroundEffect not supported!');
36
         throw new Error('JitsiStreamBackgroundEffect not supported!');
36
     }
37
     }
37
     let tflite;
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
     const modelBufferOffset = tflite._getModelBufferMemoryOffset();
63
     const modelBufferOffset = tflite._getModelBufferMemoryOffset();

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

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

Loading…
Cancel
Save