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

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