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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // @flow
  2. import { getDefaultURL } from '../../app/functions';
  3. import { APP_WILL_MOUNT } from '../app';
  4. import { SET_ROOM } from '../conference';
  5. import { MiddlewareRegistry } from '../redux';
  6. import { parseURIString } from '../util';
  7. import { addKnownDomains } from './actions';
  8. MiddlewareRegistry.register(store => next => action => {
  9. const result = next(action);
  10. switch (action.type) {
  11. case APP_WILL_MOUNT:
  12. _appWillMount(store);
  13. break;
  14. case SET_ROOM:
  15. _setRoom(store);
  16. break;
  17. }
  18. return result;
  19. });
  20. /**
  21. * Adds the domain of the app's {@code defaultURL} to the list of domains known
  22. * to the feature base/known-domains.
  23. *
  24. * @param {Object} store - The redux store.
  25. * @private
  26. * @returns {Promise}
  27. */
  28. function _appWillMount({ dispatch, getState }) {
  29. const defaultURL = parseURIString(getDefaultURL(getState));
  30. dispatch(addKnownDomains(defaultURL.host));
  31. }
  32. /**
  33. * Adds the domain of {@code locationURL} to the list of domains known to the
  34. * feature base/known-domains.
  35. *
  36. * @param {Object} store - The redux store.
  37. * @private
  38. * @returns {Promise}
  39. */
  40. function _setRoom({ dispatch, getState }) {
  41. const { locationURL } = getState()['features/base/connection'];
  42. let host;
  43. locationURL
  44. && (host = locationURL.host)
  45. && dispatch(addKnownDomains(host));
  46. }