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

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