瀏覽代碼

feat(noise-suppression): persist noise suppression setting (#13593)

* persist noise suppression setting

* address code review
factor2
Andrei Gavrilescu 2 年之前
父節點
當前提交
309f23ba94
沒有連結到貢獻者的電子郵件帳戶。

+ 0
- 1
lang/main.json 查看文件

@@ -743,7 +743,6 @@
743 743
         "newDeviceCameraTitle": "New camera detected",
744 744
         "noiseSuppressionDesktopAudioDescription": "Noise suppression can't be enabled while sharing desktop audio, please disable it and try again.",
745 745
         "noiseSuppressionFailedTitle": "Failed to start noise suppression",
746
-        "noiseSuppressionNoTrackDescription": "Please unmute your microphone first.",
747 746
         "noiseSuppressionStereoDescription": "Stereo audio noise suppression is not currently supported.",
748 747
         "oldElectronClientDescription1": "You appear to be using an old version of the Jitsi Meet client which has known security vulnerabilities. Please make sure you update to our ",
749 748
         "oldElectronClientDescription2": "latest build",

+ 9
- 1
react/features/base/tracks/loadEffects.web.ts 查看文件

@@ -1,4 +1,5 @@
1 1
 import { IStore } from '../../app/types';
2
+import { NoiseSuppressionEffect } from '../../stream-effects/noise-suppression/NoiseSuppressionEffect';
2 3
 import { createVirtualBackgroundEffect } from '../../stream-effects/virtual-background';
3 4
 
4 5
 import logger from './logger';
@@ -12,6 +13,9 @@ import logger from './logger';
12 13
 export default function loadEffects(store: IStore): Promise<any> {
13 14
     const state = store.getState();
14 15
     const virtualBackground = state['features/virtual-background'];
16
+    const noiseSuppression = state['features/noise-suppression'];
17
+    const { noiseSuppression: nsOptions } = state['features/base/config'];
18
+
15 19
 
16 20
     const backgroundPromise = virtualBackground.backgroundEffectEnabled
17 21
         ? createVirtualBackgroundEffect(virtualBackground)
@@ -22,5 +26,9 @@ export default function loadEffects(store: IStore): Promise<any> {
22 26
             })
23 27
         : Promise.resolve();
24 28
 
25
-    return Promise.all([ backgroundPromise ]);
29
+    const noiseSuppressionPromise = noiseSuppression?.enabled
30
+        ? Promise.resolve(new NoiseSuppressionEffect(nsOptions))
31
+        : Promise.resolve();
32
+
33
+    return Promise.all([ backgroundPromise, noiseSuppressionPromise ]);
26 34
 }

+ 16
- 4
react/features/noise-suppression/actions.ts 查看文件

@@ -56,8 +56,22 @@ export function setNoiseSuppressionEnabled(enabled: boolean): any {
56 56
 
57 57
         logger.info(`Attempting to set noise suppression enabled state: ${enabled}`);
58 58
 
59
+        if (enabled === noiseSuppressionEnabled) {
60
+            logger.warn(`Noise suppression enabled state already: ${enabled}`);
61
+
62
+            return;
63
+        }
64
+
65
+        // If there is no local audio, simply set the enabled state. Once an audio track is created
66
+        // the effects list will be applied.
67
+        if (!localAudio) {
68
+            dispatch(setNoiseSuppressionEnabledState(enabled));
69
+
70
+            return;
71
+        }
72
+
59 73
         try {
60
-            if (enabled && !noiseSuppressionEnabled) {
74
+            if (enabled) {
61 75
                 if (!canEnableNoiseSuppression(state, dispatch, localAudio)) {
62 76
                     return;
63 77
                 }
@@ -66,12 +80,10 @@ export function setNoiseSuppressionEnabled(enabled: boolean): any {
66 80
                 dispatch(setNoiseSuppressionEnabledState(true));
67 81
                 logger.info('Noise suppression enabled.');
68 82
 
69
-            } else if (!enabled && noiseSuppressionEnabled) {
83
+            } else {
70 84
                 await localAudio.setEffect(undefined);
71 85
                 dispatch(setNoiseSuppressionEnabledState(false));
72 86
                 logger.info('Noise suppression disabled.');
73
-            } else {
74
-                logger.warn(`Noise suppression enabled state already: ${enabled}`);
75 87
             }
76 88
         } catch (error) {
77 89
             logger.error(

+ 0
- 9
react/features/noise-suppression/functions.ts 查看文件

@@ -22,15 +22,6 @@ export function isNoiseSuppressionEnabled(state: IReduxState): boolean {
22 22
  * @returns {boolean}
23 23
  */
24 24
 export function canEnableNoiseSuppression(state: IReduxState, dispatch: IStore['dispatch'], localAudio: any): boolean {
25
-    if (!localAudio) {
26
-        dispatch(showWarningNotification({
27
-            titleKey: 'notify.noiseSuppressionFailedTitle',
28
-            descriptionKey: 'notify.noiseSuppressionNoTrackDescription'
29
-        }, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
30
-
31
-        return false;
32
-    }
33
-
34 25
     const { channelCount } = localAudio.track.getSettings();
35 26
 
36 27
     // Sharing screen audio implies an effect being applied to the local track, because currently we don't support

+ 6
- 1
react/features/noise-suppression/reducer.ts 查看文件

@@ -1,3 +1,4 @@
1
+import PersistenceRegistry from '../base/redux/PersistenceRegistry';
1 2
 import ReducerRegistry from '../base/redux/ReducerRegistry';
2 3
 
3 4
 import {
@@ -8,14 +9,18 @@ export interface INoiseSuppressionState {
8 9
     enabled: boolean;
9 10
 }
10 11
 
12
+const STORE_NAME = 'features/noise-suppression';
13
+
11 14
 const DEFAULT_STATE = {
12 15
     enabled: false
13 16
 };
14 17
 
18
+PersistenceRegistry.register(STORE_NAME);
19
+
15 20
 /**
16 21
  * Reduces the Redux actions of the feature features/noise-suppression.
17 22
  */
18
-ReducerRegistry.register<INoiseSuppressionState>('features/noise-suppression',
23
+ReducerRegistry.register<INoiseSuppressionState>(STORE_NAME,
19 24
 (state = DEFAULT_STATE, action): INoiseSuppressionState => {
20 25
     const { enabled } = action;
21 26
 

Loading…
取消
儲存