fix(virtual-backgrounds) cache wasm and model (#10190)
Prevents downloading wasm module and module each time background is changed
This commit is contained in:
parent
c37678f3bb
commit
f24e0f3622
|
@ -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 (!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());
|
||||
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;
|
||||
}
|
||||
} 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'
|
||||
}));
|
||||
}
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
const modelBufferOffset = tflite._getModelBufferMemoryOffset();
|
||||
|
|
Loading…
Reference in New Issue