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 2.1KB

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