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>
This commit is contained in:
Tudor D. Pop 2021-06-17 17:03:39 +03:00 committed by GitHub
parent be73ed9d19
commit 2ed2a8d41f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 9 deletions

View File

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

View File

@ -1,11 +1,11 @@
// @flow // @flow
import * as wasmCheck from 'wasm-check'; import { showWarningNotification } from '../../notifications/actions';
import logger from '../../virtual-background/logger';
import JitsiStreamBackgroundEffect from './JitsiStreamBackgroundEffect'; import JitsiStreamBackgroundEffect from './JitsiStreamBackgroundEffect';
import createTFLiteModule from './vendor/tflite/tflite'; import createTFLiteModule from './vendor/tflite/tflite';
import createTFLiteSIMDModule from './vendor/tflite/tflite-simd'; import createTFLiteSIMDModule from './vendor/tflite/tflite-simd';
const models = { const models = {
model96: 'libs/segm_lite_v681.tflite', model96: 'libs/segm_lite_v681.tflite',
model144: 'libs/segm_full_v679.tflite' model144: 'libs/segm_full_v679.tflite'
@ -28,18 +28,36 @@ const segmentationDimensions = {
* *
* @param {Object} virtualBackground - The virtual object that contains the background image source and * @param {Object} virtualBackground - The virtual object that contains the background image source and
* the isVirtualBackground flag that indicates if virtual image is activated. * the isVirtualBackground flag that indicates if virtual image is activated.
* @param {Function} dispatch - The Redux dispatch function.
* @returns {Promise<JitsiStreamBackgroundEffect>} * @returns {Promise<JitsiStreamBackgroundEffect>}
*/ */
export async function createVirtualBackgroundEffect(virtualBackground: Object) { export async function createVirtualBackgroundEffect(virtualBackground: Object, dispatch: Function) {
if (!MediaStreamTrack.prototype.getSettings && !MediaStreamTrack.prototype.getConstraints) { if (!MediaStreamTrack.prototype.getSettings && !MediaStreamTrack.prototype.getConstraints) {
throw new Error('JitsiStreamBackgroundEffect not supported!'); throw new Error('JitsiStreamBackgroundEffect not supported!');
} }
let tflite; let tflite;
let wasmCheck;
// Checks if WebAssembly feature is supported or enabled by/in the browser.
// Conditional import of wasm-check package is done to prevent
// the browser from crashing when the user opens the app.
try {
wasmCheck = require('wasm-check');
if (wasmCheck?.feature?.simd) {
tflite = await createTFLiteSIMDModule();
} else {
tflite = await createTFLiteModule();
}
} catch (err) {
logger.error('Looks like WebAssembly is disabled or not supported on this browser');
dispatch(showWarningNotification({
titleKey: 'virtualBackground.webAssemblyWarning',
description: 'WebAssembly disabled or not supported by this browser'
}));
return;
if (wasmCheck.feature.simd) {
tflite = await createTFLiteSIMDModule();
} else {
tflite = await createTFLiteModule();
} }
const modelBufferOffset = tflite._getModelBufferMemoryOffset(); const modelBufferOffset = tflite._getModelBufferMemoryOffset();

View File

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