選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

middleware.ts 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 { setAudioMuted } from '../base/media/actions';
  5. import { MEDIA_TYPE } from '../base/media/constants';
  6. import { raiseHand } from '../base/participants/actions';
  7. import { getLocalParticipant } from '../base/participants/functions';
  8. import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
  9. import { playSound, registerSound, unregisterSound } from '../base/sounds/actions';
  10. import { hideNotification, showNotification } from '../notifications/actions';
  11. import { NOTIFICATION_TIMEOUT_TYPE } from '../notifications/constants';
  12. import { isForceMuted } from '../participants-pane/functions';
  13. import { isAudioMuteButtonDisabled } from '../toolbox/functions.any';
  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: any) => {
  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. // Display the talk while muted notification only when the audio button is not disabled.
  43. if (!isAudioMuteButtonDisabled(state)) {
  44. const forceMuted = isForceMuted(local, MEDIA_TYPE.AUDIO, state);
  45. const notification = await dispatch(showNotification({
  46. titleKey: 'toolbar.talkWhileMutedPopup',
  47. customActionNameKey: [ forceMuted ? 'notify.raiseHandAction' : 'notify.unmute' ],
  48. customActionHandler: [ () => dispatch(forceMuted ? raiseHand(true) : setAudioMuted(false)) ]
  49. }, NOTIFICATION_TIMEOUT_TYPE.LONG));
  50. const { soundsTalkWhileMuted } = getState()['features/base/settings'];
  51. if (soundsTalkWhileMuted) {
  52. dispatch(playSound(TALK_WHILE_MUTED_SOUND_ID));
  53. }
  54. if (notification) {
  55. // we store the last start muted notification id that we showed,
  56. // so we can hide it when unmuted mic is detected
  57. dispatch(setCurrentNotificationUid(notification.uid));
  58. }
  59. }
  60. });
  61. break;
  62. }
  63. }
  64. return result;
  65. });