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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // @flow
  2. import { APP_WILL_MOUNT, APP_WILL_UNMOUNT } from '../base/app';
  3. import { getCurrentConference } from '../base/conference';
  4. import { getLocalParticipant, participantUpdated } from '../base/participants';
  5. import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
  6. import { playSound, registerSound, unregisterSound } from '../base/sounds';
  7. import { TOGGLE_E2EE } from './actionTypes';
  8. import { toggleE2EE } from './actions';
  9. import { E2EE_OFF_SOUND_ID, E2EE_ON_SOUND_ID } from './constants';
  10. import logger from './logger';
  11. import { E2EE_OFF_SOUND_FILE, E2EE_ON_SOUND_FILE } from './sounds';
  12. /**
  13. * Middleware that captures actions related to E2EE.
  14. *
  15. * @param {Store} store - The redux store.
  16. * @returns {Function}
  17. */
  18. MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
  19. switch (action.type) {
  20. case APP_WILL_MOUNT:
  21. dispatch(registerSound(
  22. E2EE_OFF_SOUND_ID,
  23. E2EE_OFF_SOUND_FILE));
  24. dispatch(registerSound(
  25. E2EE_ON_SOUND_ID,
  26. E2EE_ON_SOUND_FILE));
  27. break;
  28. case APP_WILL_UNMOUNT:
  29. dispatch(unregisterSound(E2EE_OFF_SOUND_ID));
  30. dispatch(unregisterSound(E2EE_ON_SOUND_ID));
  31. break;
  32. case TOGGLE_E2EE: {
  33. const conference = getCurrentConference(getState);
  34. if (conference) {
  35. logger.debug(`E2EE will be ${action.enabled ? 'enabled' : 'disabled'}`);
  36. conference.toggleE2EE(action.enabled);
  37. // Broadcast that we enabled / disabled E2EE.
  38. const participant = getLocalParticipant(getState);
  39. dispatch(participantUpdated({
  40. e2eeEnabled: action.enabled,
  41. id: participant.id,
  42. local: true
  43. }));
  44. const soundID = action.enabled ? E2EE_ON_SOUND_ID : E2EE_OFF_SOUND_ID;
  45. dispatch(playSound(soundID));
  46. }
  47. break;
  48. }
  49. }
  50. return next(action);
  51. });
  52. /**
  53. * Set up state change listener to perform maintenance tasks when the conference
  54. * is left or failed.
  55. */
  56. StateListenerRegistry.register(
  57. state => getCurrentConference(state),
  58. (conference, { dispatch }, previousConference) => {
  59. if (previousConference) {
  60. dispatch(toggleE2EE(false));
  61. }
  62. });