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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 { setAudioMuted } from '../base/media';
  6. import { MiddlewareRegistry } from '../base/redux';
  7. import { playSound, registerSound, unregisterSound } from '../base/sounds';
  8. import {
  9. hideNotification,
  10. showNotification
  11. } from '../notifications';
  12. import { setCurrentNotificationUid } from './actions';
  13. import { TALK_WHILE_MUTED_SOUND_ID } from './constants';
  14. import { TALK_WHILE_MUTED_SOUND_FILE } from './sounds';
  15. MiddlewareRegistry.register(store => next => action => {
  16. const result = next(action);
  17. const { dispatch, getState } = store;
  18. const { conference } = action;
  19. switch (action.type) {
  20. case APP_WILL_MOUNT:
  21. dispatch(registerSound(TALK_WHILE_MUTED_SOUND_ID, TALK_WHILE_MUTED_SOUND_FILE));
  22. break;
  23. case APP_WILL_UNMOUNT:
  24. dispatch(unregisterSound(TALK_WHILE_MUTED_SOUND_ID));
  25. break;
  26. case CONFERENCE_JOINED: {
  27. conference.on(
  28. JitsiConferenceEvents.TRACK_MUTE_CHANGED,
  29. track => {
  30. const { currentNotificationUid } = getState()['features/talk-while-muted'];
  31. if (currentNotificationUid && track.isAudioTrack() && track.isLocal() && !track.isMuted()) {
  32. dispatch(hideNotification(currentNotificationUid));
  33. dispatch(setCurrentNotificationUid());
  34. }
  35. });
  36. conference.on(
  37. JitsiConferenceEvents.TALK_WHILE_MUTED, () => {
  38. const notification = showNotification({
  39. titleKey: 'toolbar.talkWhileMutedPopup',
  40. customActionNameKey: 'notify.unmute',
  41. customActionHandler: () => dispatch(setAudioMuted(false))
  42. });
  43. dispatch(notification);
  44. dispatch(playSound(TALK_WHILE_MUTED_SOUND_ID));
  45. // we store the last start muted notification id that we showed,
  46. // so we can hide it when unmuted mic is detected
  47. dispatch(setCurrentNotificationUid(notification.uid));
  48. });
  49. break;
  50. }
  51. }
  52. return result;
  53. });