2022-07-20 12:31:17 +00:00
|
|
|
import { IState } from '../app/types';
|
2022-10-11 10:47:54 +00:00
|
|
|
import { showWarningNotification } from '../notifications/actions';
|
2022-09-06 17:32:20 +00:00
|
|
|
import { NOTIFICATION_TIMEOUT_TYPE } from '../notifications/constants';
|
2022-10-11 10:47:54 +00:00
|
|
|
import { isScreenAudioShared } from '../screen-share/functions';
|
2022-07-20 12:31:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Is noise suppression currently enabled.
|
|
|
|
*
|
|
|
|
* @param {IState} state - The state of the application.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
export function isNoiseSuppressionEnabled(state: IState): boolean {
|
|
|
|
return state['features/noise-suppression'].enabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verify if noise suppression can be enabled in the current state.
|
|
|
|
*
|
|
|
|
* @param {*} state - Redux state.
|
|
|
|
* @param {*} dispatch - Redux dispatch.
|
|
|
|
* @param {*} localAudio - Current local audio track.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
export function canEnableNoiseSuppression(state: IState, dispatch: Function, localAudio: any): boolean {
|
2022-08-04 13:51:13 +00:00
|
|
|
if (!localAudio) {
|
|
|
|
dispatch(showWarningNotification({
|
|
|
|
titleKey: 'notify.noiseSuppressionFailedTitle',
|
|
|
|
descriptionKey: 'notify.noiseSuppressionNoTrackDescription'
|
|
|
|
}, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-07-20 12:31:17 +00:00
|
|
|
const { channelCount } = localAudio.track.getSettings();
|
|
|
|
|
|
|
|
// Sharing screen audio implies an effect being applied to the local track, because currently we don't support
|
|
|
|
// more then one effect at a time the user has to choose between sharing audio or having noise suppression active.
|
|
|
|
if (isScreenAudioShared(state)) {
|
|
|
|
dispatch(showWarningNotification({
|
|
|
|
titleKey: 'notify.noiseSuppressionFailedTitle',
|
|
|
|
descriptionKey: 'notify.noiseSuppressionDesktopAudioDescription'
|
|
|
|
}, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stereo audio tracks aren't currently supported, make sure the current local track is mono
|
|
|
|
if (channelCount > 1) {
|
|
|
|
dispatch(showWarningNotification({
|
|
|
|
titleKey: 'notify.noiseSuppressionFailedTitle',
|
|
|
|
descriptionKey: 'notify.noiseSuppressionStereoDescription'
|
|
|
|
}, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|