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

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* @flow */
  2. import { PROFILE_UPDATED } from './actionTypes';
  3. import MiddlewareRegistry from '../redux/MiddlewareRegistry';
  4. import { participantUpdated } from '../participants';
  5. import { getProfile } from '../profile';
  6. import { toState } from '../redux';
  7. /**
  8. * A MiddleWare to update the local participant when the profile
  9. * is updated.
  10. *
  11. * @param {Store} store - The redux store.
  12. * @returns {Function}
  13. */
  14. MiddlewareRegistry.register(store => next => action => {
  15. const result = next(action);
  16. switch (action.type) {
  17. case PROFILE_UPDATED:
  18. _updateLocalParticipant(store);
  19. }
  20. return result;
  21. });
  22. /**
  23. * Updates the local participant according to profile changes.
  24. *
  25. * @param {Store} store - The redux store.
  26. * @returns {void}
  27. */
  28. function _updateLocalParticipant(store) {
  29. const profile = getProfile(toState(store));
  30. const newLocalParticipant = {
  31. email: profile.email,
  32. local: true,
  33. name: profile.displayName
  34. };
  35. store.dispatch(participantUpdated(newLocalParticipant));
  36. }