"Fossies" - the Fresh Open Source Software Archive 
Member "jitsi-meet-7313/react/features/noise-suppression/actions.ts" (2 Jun 2023, 3111 Bytes) of package /linux/misc/jitsi-meet-7313.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the last
Fossies "Diffs" side-by-side code changes report for "actions.ts":
jitsi-meet_8319_vs_jitsi-meet_8615.
1 import { IStore } from '../app/types';
2 import { getLocalJitsiAudioTrack } from '../base/tracks/functions';
3 import { showErrorNotification } from '../notifications/actions';
4 import { NOTIFICATION_TIMEOUT_TYPE } from '../notifications/constants';
5 import { NoiseSuppressionEffect } from '../stream-effects/noise-suppression/NoiseSuppressionEffect';
6
7 import { SET_NOISE_SUPPRESSION_ENABLED } from './actionTypes';
8 import { canEnableNoiseSuppression, isNoiseSuppressionEnabled } from './functions';
9 import logger from './logger';
10
11 /**
12 * Updates the noise suppression active state.
13 *
14 * @param {boolean} enabled - Is noise suppression enabled.
15 * @returns {{
16 * type: SET_NOISE_SUPPRESSION_STATE,
17 * enabled: boolean
18 * }}
19 */
20 export function setNoiseSuppressionEnabledState(enabled: boolean): any {
21 return {
22 type: SET_NOISE_SUPPRESSION_ENABLED,
23 enabled
24 };
25 }
26
27 /**
28 * Enabled/disable noise suppression depending on the current state.
29 *
30 * @returns {Function}
31 */
32 export function toggleNoiseSuppression(): any {
33 return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
34 if (isNoiseSuppressionEnabled(getState())) {
35 dispatch(setNoiseSuppressionEnabled(false));
36 } else {
37 dispatch(setNoiseSuppressionEnabled(true));
38 }
39 };
40 }
41
42 /**
43 * Attempt to enable or disable noise suppression using the {@link NoiseSuppressionEffect}.
44 *
45 * @param {boolean} enabled - Enable or disable noise suppression.
46 *
47 * @returns {Function}
48 */
49 export function setNoiseSuppressionEnabled(enabled: boolean): any {
50 return async (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
51 const state = getState();
52
53 const { noiseSuppression: nsOptions } = state['features/base/config'];
54 const localAudio = getLocalJitsiAudioTrack(state);
55 const noiseSuppressionEnabled = isNoiseSuppressionEnabled(state);
56
57 logger.info(`Attempting to set noise suppression enabled state: ${enabled}`);
58
59 try {
60 if (enabled && !noiseSuppressionEnabled) {
61 if (!canEnableNoiseSuppression(state, dispatch, localAudio)) {
62 return;
63 }
64
65 await localAudio.setEffect(new NoiseSuppressionEffect(nsOptions));
66 dispatch(setNoiseSuppressionEnabledState(true));
67 logger.info('Noise suppression enabled.');
68
69 } else if (!enabled && noiseSuppressionEnabled) {
70 await localAudio.setEffect(undefined);
71 dispatch(setNoiseSuppressionEnabledState(false));
72 logger.info('Noise suppression disabled.');
73 } else {
74 logger.warn(`Noise suppression enabled state already: ${enabled}`);
75 }
76 } catch (error) {
77 logger.error(
78 `Failed to set noise suppression enabled to: ${enabled}`,
79 error
80 );
81
82 dispatch(showErrorNotification({
83 titleKey: 'notify.noiseSuppressionFailedTitle'
84 }, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
85 }
86 };
87 }