您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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 { SET_E2EE_KEY } from './actionTypes';
  6. import { setE2EEKey } 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 SET_E2EE_KEY: {
  17. const conference = getCurrentConference(getState);
  18. if (conference) {
  19. logger.debug(`New E2EE key: ${action.key}`);
  20. conference.setE2EEKey(action.key);
  21. // Broadccast that we enabled / disabled E2EE.
  22. const participant = getLocalParticipant(getState);
  23. dispatch(participantUpdated({
  24. e2eeEnabled: Boolean(action.key),
  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(setE2EEKey(undefined));
  43. }
  44. });