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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // @flow
  2. import { getCurrentConference } from '../base/conference';
  3. import { getLocalParticipant, participantUpdated } from '../base/participants';
  4. import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
  5. import { TOGGLE_E2EE } from './actionTypes';
  6. import { toggleE2EE } from './actions';
  7. import logger from './logger';
  8. /**
  9. * Middleware that captures actions related to E2EE.
  10. *
  11. * @param {Store} store - The redux store.
  12. * @returns {Function}
  13. */
  14. MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
  15. switch (action.type) {
  16. case TOGGLE_E2EE: {
  17. const conference = getCurrentConference(getState);
  18. if (conference) {
  19. logger.debug(`E2EE will be ${action.enabled ? 'enabled' : 'disabled'}`);
  20. conference.toggleE2EE(action.enabled);
  21. // Broadccast that we enabled / disabled E2EE.
  22. const participant = getLocalParticipant(getState);
  23. dispatch(participantUpdated({
  24. e2eeEnabled: action.enabled,
  25. id: participant.id,
  26. local: true
  27. }));
  28. }
  29. break;
  30. }
  31. }
  32. return next(action);
  33. });
  34. /**
  35. * Set up state change listener to perform maintenance tasks when the conference
  36. * is left or failed.
  37. */
  38. StateListenerRegistry.register(
  39. state => getCurrentConference(state),
  40. (conference, { dispatch }, previousConference) => {
  41. if (previousConference) {
  42. dispatch(toggleE2EE(false));
  43. }
  44. });