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.9KB

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