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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // @flow
  2. import { APP_WILL_MOUNT } from '../app';
  3. import { ReducerRegistry } from '../redux';
  4. import { PersistenceRegistry } from '../storage';
  5. import { ADD_KNOWN_DOMAINS } from './actionTypes';
  6. /**
  7. * The default list of domains known to the feature base/known-domains.
  8. * Generally, it should be in sync with the domains associated with the app
  9. * through its manifest (in other words, Universal Links, deep linking). Anyway,
  10. * we need a hardcoded list because it has proven impossible to programmatically
  11. * read the information out of the app's manifests: App Store strips the
  12. * associated domains manifest out of the app so it's never downloaded on the
  13. * client and we did not spend a lot of effort to read the associated domains
  14. * out of the Andorid manifest.
  15. */
  16. export const DEFAULT_STATE = [
  17. 'alpha.jitsi.net',
  18. 'beta.meet.jit.si',
  19. 'meet.jit.si',
  20. '8x8.vc'
  21. ];
  22. const STORE_NAME = 'features/base/known-domains';
  23. PersistenceRegistry.register(STORE_NAME);
  24. ReducerRegistry.register(STORE_NAME, (state = DEFAULT_STATE, action) => {
  25. switch (action.type) {
  26. case ADD_KNOWN_DOMAINS:
  27. return _addKnownDomains(state, action.knownDomains);
  28. case APP_WILL_MOUNT:
  29. // In case persistence has deserialized a weird redux state:
  30. return _addKnownDomains(state, DEFAULT_STATE);
  31. default:
  32. return state;
  33. }
  34. });
  35. /**
  36. * Adds an array of known domains to the list of domains known to the feature
  37. * base/known-domains.
  38. *
  39. * @param {Object} state - The redux state.
  40. * @param {Array<string>} knownDomains - The array of known domains to add to
  41. * the list of domains known to the feature base/known-domains.
  42. * @private
  43. * @returns {Object} The next redux state.
  44. */
  45. function _addKnownDomains(state, knownDomains) {
  46. // In case persistence has deserialized a weird redux state:
  47. let nextState = Array.isArray(state) ? state : [];
  48. if (Array.isArray(knownDomains)) {
  49. nextState = Array.from(state);
  50. for (let knownDomain of knownDomains) {
  51. knownDomain = knownDomain.toLowerCase();
  52. !nextState.includes(knownDomain) && nextState.push(knownDomain);
  53. }
  54. }
  55. return nextState;
  56. }