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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // @flow
  2. import { setAudioOnly } from '../conference';
  3. import { getLocalParticipant, participantUpdated } from '../participants';
  4. import { getProfile } from '../profile';
  5. import { MiddlewareRegistry, toState } from '../redux';
  6. import { PROFILE_UPDATED } from './actionTypes';
  7. /**
  8. * A middleWare to update the local participant when the profile is updated.
  9. *
  10. * @param {Store} store - The redux store.
  11. * @returns {Function}
  12. */
  13. MiddlewareRegistry.register(store => next => action => {
  14. const result = next(action);
  15. switch (action.type) {
  16. case PROFILE_UPDATED:
  17. _updateLocalParticipant(store);
  18. _maybeUpdateStartAudioOnly(store, action);
  19. }
  20. return result;
  21. });
  22. /**
  23. * Updates startAudioOnly flag if it's updated in the profile.
  24. *
  25. * @private
  26. * @param {Store} store - The redux store.
  27. * @param {Object} action - The redux action.
  28. * @returns {void}
  29. */
  30. function _maybeUpdateStartAudioOnly(store, action) {
  31. const { profile } = action;
  32. if (typeof profile.startAudioOnly === 'boolean') {
  33. store.dispatch(setAudioOnly(profile.startAudioOnly));
  34. }
  35. }
  36. /**
  37. * Updates the local participant according to profile changes.
  38. *
  39. * @param {Store} store - The redux store.
  40. * @returns {void}
  41. */
  42. function _updateLocalParticipant(store) {
  43. const state = toState(store);
  44. const localParticipant = getLocalParticipant(state);
  45. const profile = getProfile(state);
  46. store.dispatch(participantUpdated({
  47. // Identify that the participant to update i.e. the local participant:
  48. id: localParticipant && localParticipant.id,
  49. local: true,
  50. // Specify the updates to be applied to the identified participant:
  51. email: profile.email,
  52. name: profile.displayName
  53. }));
  54. }