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.

reducer.js 2.1KB

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