Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

middleware.ts 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app/actionTypes';
  2. import { CONFERENCE_JOINED } from '../base/conference/actionTypes';
  3. import { JitsiConferenceEvents } from '../base/lib-jitsi-meet';
  4. import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
  5. import { playSound, registerSound, unregisterSound } from '../base/sounds/actions';
  6. import { hideNotification, showNotification } from '../notifications/actions';
  7. import { NOTIFICATION_TIMEOUT_TYPE } from '../notifications/constants';
  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: any) => {
  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, async () => {
  35. const notification = await dispatch(showNotification({
  36. titleKey: 'toolbar.noisyAudioInputTitle',
  37. descriptionKey: 'toolbar.noisyAudioInputDesc'
  38. }, NOTIFICATION_TIMEOUT_TYPE.MEDIUM));
  39. dispatch(playSound(NOISY_AUDIO_INPUT_SOUND_ID));
  40. if (notification) {
  41. // we store the last notification id so we can hide it if the mic is muted
  42. dispatch(setNoisyAudioInputNotificationUid(notification.uid));
  43. }
  44. });
  45. break;
  46. }
  47. }
  48. return result;
  49. });