You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

functions.ts 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { IReduxState, IStore } from '../app/types';
  2. import { showWarningNotification } from '../notifications/actions';
  3. import { NOTIFICATION_TIMEOUT_TYPE } from '../notifications/constants';
  4. import { isScreenAudioShared } from '../screen-share/functions';
  5. /**
  6. * Is noise suppression currently enabled.
  7. *
  8. * @param {IReduxState} state - The state of the application.
  9. * @returns {boolean}
  10. */
  11. export function isNoiseSuppressionEnabled(state: IReduxState): boolean {
  12. return state['features/noise-suppression'].enabled;
  13. }
  14. /**
  15. * Verify if noise suppression can be enabled in the current state.
  16. *
  17. * @param {*} state - Redux state.
  18. * @param {*} dispatch - Redux dispatch.
  19. * @param {*} localAudio - Current local audio track.
  20. * @returns {boolean}
  21. */
  22. export function canEnableNoiseSuppression(state: IReduxState, dispatch: IStore['dispatch'], localAudio: any): boolean {
  23. const { channelCount } = localAudio.track.getSettings();
  24. // Sharing screen audio implies an effect being applied to the local track, because currently we don't support
  25. // more then one effect at a time the user has to choose between sharing audio or having noise suppression active.
  26. if (isScreenAudioShared(state)) {
  27. dispatch(showWarningNotification({
  28. titleKey: 'notify.noiseSuppressionFailedTitle',
  29. descriptionKey: 'notify.noiseSuppressionDesktopAudioDescription'
  30. }, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
  31. return false;
  32. }
  33. // Stereo audio tracks aren't currently supported, make sure the current local track is mono
  34. if (channelCount > 1) {
  35. dispatch(showWarningNotification({
  36. titleKey: 'notify.noiseSuppressionFailedTitle',
  37. descriptionKey: 'notify.noiseSuppressionStereoDescription'
  38. }, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
  39. return false;
  40. }
  41. return true;
  42. }