2023-02-02 13:12:31 +02:00
|
|
|
import { IStore } from '../../app/types';
|
2023-07-25 10:57:01 +03:00
|
|
|
import { NoiseSuppressionEffect } from '../../stream-effects/noise-suppression/NoiseSuppressionEffect';
|
2021-03-12 16:50:57 +01:00
|
|
|
import { createVirtualBackgroundEffect } from '../../stream-effects/virtual-background';
|
2020-01-28 11:06:03 +01:00
|
|
|
|
|
|
|
|
import logger from './logger';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Loads the enabled stream effects.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} store - The Redux store.
|
2023-08-17 11:21:20 +02:00
|
|
|
* @returns {Promise} - A Promise which resolves when all effects are created.
|
2020-01-28 11:06:03 +01:00
|
|
|
*/
|
2023-02-02 13:12:31 +02:00
|
|
|
export default function loadEffects(store: IStore): Promise<any> {
|
2024-10-31 12:49:57 -05:00
|
|
|
const start = window.performance.now();
|
2020-01-28 11:06:03 +01:00
|
|
|
const state = store.getState();
|
2021-03-12 16:50:57 +01:00
|
|
|
const virtualBackground = state['features/virtual-background'];
|
2023-07-25 10:57:01 +03:00
|
|
|
const noiseSuppression = state['features/noise-suppression'];
|
|
|
|
|
const { noiseSuppression: nsOptions } = state['features/base/config'];
|
|
|
|
|
|
2020-01-28 11:06:03 +01:00
|
|
|
|
2021-03-12 16:50:57 +01:00
|
|
|
const backgroundPromise = virtualBackground.backgroundEffectEnabled
|
|
|
|
|
? createVirtualBackgroundEffect(virtualBackground)
|
2023-02-02 13:12:31 +02:00
|
|
|
.catch((error: Error) => {
|
2021-02-18 17:52:47 +02:00
|
|
|
logger.error('Failed to obtain the background effect instance with error: ', error);
|
2020-01-28 11:06:03 +01:00
|
|
|
|
|
|
|
|
return Promise.resolve();
|
|
|
|
|
})
|
|
|
|
|
: Promise.resolve();
|
|
|
|
|
|
2023-07-25 10:57:01 +03:00
|
|
|
const noiseSuppressionPromise = noiseSuppression?.enabled
|
|
|
|
|
? Promise.resolve(new NoiseSuppressionEffect(nsOptions))
|
|
|
|
|
: Promise.resolve();
|
|
|
|
|
|
2024-10-31 12:49:57 -05:00
|
|
|
return Promise.all([ backgroundPromise, noiseSuppressionPromise ]).then(effectsArray => {
|
|
|
|
|
const end = window.performance.now();
|
|
|
|
|
|
|
|
|
|
logger.debug(`(TIME) loadEffects() start=${start}, end=${end}, time=${end - start}`);
|
|
|
|
|
|
|
|
|
|
return effectsArray;
|
|
|
|
|
});
|
2020-01-28 11:06:03 +01:00
|
|
|
}
|