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

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