Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

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

Avram Tudorf24e0f36221a
diff --git a/react/features/stream-effects/virtual-background/index.js b/react/features/stream-effects/virtual-background/index.js
index 634f8f6f55..fe754dfcb4 100644
--- a/react/features/stream-effects/virtual-background/index.js
+++ b/react/features/stream-effects/virtual-background/index.js
@@ -12,6 +12,10 @@ const models = {
model144: 'libs/segm_full_v679.tflite'
};
+let tflite;
+let wasmCheck;
+let isWasmDisabled = false;
+
const segmentationDimensions = {
model96: {
height: 96,
@@ -36,38 +40,39 @@ export async function createVirtualBackgroundEffect(virtualBackground: Object, d
if (!MediaStreamTrack.prototype.getSettings && !MediaStreamTrack.prototype.getConstraints) {
throw new Error('JitsiStreamBackgroundEffect not supported!');
}
- 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');
- const tfliteTimeout = 10000;
-
- if (wasmCheck?.feature?.simd) {
- tflite = await timeout(tfliteTimeout, createTFLiteSIMDModule());
- } else {
- tflite = await timeout(tfliteTimeout, createTFLiteModule());
- }
- } catch (err) {
- if (err?.message === '408') {
- logger.error('Failed to download tflite model!');
- dispatch(showWarningNotification({
- titleKey: 'virtualBackground.backgroundEffectError'
- }));
- } else {
- 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'
- }));
+ if (!tflite && !isWasmDisabled) {
+ try {
+ wasmCheck = require('wasm-check');
+ const tfliteTimeout = 10000;
+
+ if (wasmCheck?.feature?.simd) {
+ tflite = await timeout(tfliteTimeout, createTFLiteSIMDModule());
+ } else {
+ tflite = await timeout(tfliteTimeout, createTFLiteModule());
+ }
+ } catch (err) {
+ isWasmDisabled = true;
+
+ if (err?.message === '408') {
+ logger.error('Failed to download tflite model!');
+ dispatch(showWarningNotification({
+ titleKey: 'virtualBackground.backgroundEffectError'
+ }));
+ } else {
+ 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;
}
-
- return;
-
}
const modelBufferOffset = tflite._getModelBufferMemoryOffset();