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 { APP_WILL_MOUNT } from '../../app';
  3. import { SET_ROOM } from '../conference';
  4. import { MiddlewareRegistry } from '../redux';
  5. import { parseURIString } from '../util';
  6. import { addKnownDomains } from './actions';
  7. MiddlewareRegistry.register(store => next => action => {
  8. const result = next(action);
  9. switch (action.type) {
  10. case APP_WILL_MOUNT:
  11. _appWillMount(store);
  12. break;
  13. case SET_ROOM:
  14. _setRoom(store);
  15. break;
  16. }
  17. return result;
  18. });
  19. /**
  20. * Adds the domain of the app's {@code defaultURL} to the list of domains known
  21. * to the feature base/known-domains.
  22. *
  23. * @param {Object} store - The redux store.
  24. * @private
  25. * @returns {Promise}
  26. */
  27. function _appWillMount({ dispatch, getState }) {
  28. const defaultURL
  29. = parseURIString(getState()['features/app'].app._getDefaultURL());
  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. }