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

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