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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // @flow
  2. import { setAudioOnly } from '../conference';
  3. import { getLocalParticipant, participantUpdated } from '../participants';
  4. import { MiddlewareRegistry, toState } from '../redux';
  5. import { PROFILE_UPDATED } from './actionTypes';
  6. /**
  7. * The middleware of the feature base/profile. Distributes changes to the state
  8. * of base/profile to the states of other features computed from the state of
  9. * base/profile.
  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. _maybeSetAudioOnly(store, action);
  20. }
  21. return result;
  22. });
  23. /**
  24. * Updates {@code startAudioOnly} flag if it's updated in the profile.
  25. *
  26. * @param {Store} store - The redux store.
  27. * @param {Object} action - The redux action.
  28. * @private
  29. * @returns {void}
  30. */
  31. function _maybeSetAudioOnly(
  32. { dispatch },
  33. { profile: { startAudioOnly } }) {
  34. if (typeof startAudioOnly === 'boolean') {
  35. dispatch(setAudioOnly(startAudioOnly));
  36. }
  37. }
  38. /**
  39. * Updates the local participant according to profile changes.
  40. *
  41. * @param {Store} store - The redux store.
  42. * @private
  43. * @returns {void}
  44. */
  45. function _updateLocalParticipant(store) {
  46. const state = toState(store);
  47. const localParticipant = getLocalParticipant(state);
  48. const profile = state['features/base/profile'];
  49. store.dispatch(participantUpdated({
  50. // Identify that the participant to update i.e. the local participant:
  51. id: localParticipant && localParticipant.id,
  52. local: true,
  53. // Specify the updates to be applied to the identified participant:
  54. email: profile.email,
  55. name: profile.displayName
  56. }));
  57. }