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.

middleware.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // @flow
  2. import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app';
  3. import { CONFERENCE_JOINED } from '../base/conference';
  4. import { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
  5. import { MiddlewareRegistry } from '../base/redux';
  6. import { playSound, registerSound, unregisterSound } from '../base/sounds';
  7. import { hideNotification, showNotification } from '../notifications';
  8. import { setNoisyAudioInputNotificationUid } from './actions';
  9. import { NOISY_AUDIO_INPUT_SOUND_ID } from './constants';
  10. import { NOISY_AUDIO_INPUT_SOUND_FILE } from './sounds';
  11. MiddlewareRegistry.register(store => next => action => {
  12. const result = next(action);
  13. switch (action.type) {
  14. case APP_WILL_MOUNT:
  15. store.dispatch(registerSound(NOISY_AUDIO_INPUT_SOUND_ID, NOISY_AUDIO_INPUT_SOUND_FILE));
  16. break;
  17. case APP_WILL_UNMOUNT:
  18. store.dispatch(unregisterSound(NOISY_AUDIO_INPUT_SOUND_ID));
  19. break;
  20. case CONFERENCE_JOINED: {
  21. const { dispatch, getState } = store;
  22. const { conference } = action;
  23. conference.on(
  24. JitsiConferenceEvents.TRACK_MUTE_CHANGED,
  25. track => {
  26. const { noisyAudioInputNotificationUid } = getState()['features/noise-detection'];
  27. // Hide the notification in case the user mutes the microphone
  28. if (noisyAudioInputNotificationUid && track.isAudioTrack() && track.isLocal() && track.isMuted()) {
  29. dispatch(hideNotification(noisyAudioInputNotificationUid));
  30. dispatch(setNoisyAudioInputNotificationUid());
  31. }
  32. });
  33. conference.on(
  34. JitsiConferenceEvents.NOISY_MIC, () => {
  35. const notification = showNotification({
  36. titleKey: 'toolbar.noisyAudioInputTitle',
  37. descriptionKey: 'toolbar.noisyAudioInputDesc'
  38. });
  39. dispatch(notification);
  40. dispatch(playSound(NOISY_AUDIO_INPUT_SOUND_ID));
  41. // we store the last notification id so we can hide it if the mic is muted
  42. dispatch(setNoisyAudioInputNotificationUid(notification.uid));
  43. });
  44. break;
  45. }
  46. }
  47. return result;
  48. });