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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. import { JITSI_KNOWN_DOMAINS } from './constants';
  8. MiddlewareRegistry.register(store => next => action => {
  9. const result = next(action);
  10. switch (action.type) {
  11. case APP_WILL_MOUNT:
  12. _ensureDefaultServer(store);
  13. break;
  14. case SET_ROOM:
  15. _parseAndAddKnownDomain(store);
  16. break;
  17. }
  18. return result;
  19. });
  20. /**
  21. * Ensures presence of the default server in the known domains list.
  22. *
  23. * @param {Object} store - The redux store.
  24. * @private
  25. * @returns {Promise}
  26. */
  27. function _ensureDefaultServer({ dispatch, getState }) {
  28. const { app } = getState()['features/app'];
  29. const defaultURL = parseURIString(app._getDefaultURL());
  30. dispatch(addKnownDomains([
  31. defaultURL.host,
  32. ...JITSI_KNOWN_DOMAINS
  33. ]));
  34. }
  35. /**
  36. * Retrieves the domain name of a room upon join and stores it in the known
  37. * domain list, if not present yet.
  38. *
  39. * @param {Object} store - The redux store.
  40. * @private
  41. * @returns {Promise}
  42. */
  43. function _parseAndAddKnownDomain({ dispatch, getState }) {
  44. const { locationURL } = getState()['features/base/connection'];
  45. locationURL
  46. && locationURL.host
  47. && dispatch(addKnownDomains(locationURL.host));
  48. }