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

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