2022-07-19 07:58:56 +00:00
|
|
|
import PersistenceRegistry from '../redux/PersistenceRegistry';
|
|
|
|
import ReducerRegistry from '../redux/ReducerRegistry';
|
2018-05-14 15:55:40 +00:00
|
|
|
|
|
|
|
import { ADD_KNOWN_DOMAINS } from './actionTypes';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The default list of domains known to the feature base/known-domains.
|
|
|
|
* Generally, it should be in sync with the domains associated with the app
|
|
|
|
* through its manifest (in other words, Universal Links, deep linking). Anyway,
|
|
|
|
* we need a hardcoded list because it has proven impossible to programmatically
|
|
|
|
* read the information out of the app's manifests: App Store strips the
|
|
|
|
* associated domains manifest out of the app so it's never downloaded on the
|
|
|
|
* client and we did not spend a lot of effort to read the associated domains
|
2022-07-14 07:10:08 +00:00
|
|
|
* out of the Android manifest.
|
2018-05-14 15:55:40 +00:00
|
|
|
*/
|
|
|
|
export const DEFAULT_STATE = [
|
2019-05-01 17:28:32 +00:00
|
|
|
'alpha.jitsi.net',
|
2018-05-14 15:55:40 +00:00
|
|
|
'beta.meet.jit.si',
|
2019-04-24 13:19:47 +00:00
|
|
|
'meet.jit.si',
|
|
|
|
'8x8.vc'
|
2018-05-14 15:55:40 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
const STORE_NAME = 'features/base/known-domains';
|
|
|
|
|
|
|
|
PersistenceRegistry.register(STORE_NAME);
|
|
|
|
|
2022-09-05 09:05:07 +00:00
|
|
|
export type IKnownDomainsState = Array<string>;
|
|
|
|
|
|
|
|
ReducerRegistry.register<IKnownDomainsState>(STORE_NAME, (state = DEFAULT_STATE, action): IKnownDomainsState => {
|
2018-05-14 15:55:40 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case ADD_KNOWN_DOMAINS:
|
|
|
|
return _addKnownDomains(state, action.knownDomains);
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds an array of known domains to the list of domains known to the feature
|
|
|
|
* base/known-domains.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The redux state.
|
|
|
|
* @param {Array<string>} knownDomains - The array of known domains to add to
|
|
|
|
* the list of domains known to the feature base/known-domains.
|
|
|
|
* @private
|
|
|
|
* @returns {Object} The next redux state.
|
|
|
|
*/
|
2022-09-05 09:05:07 +00:00
|
|
|
function _addKnownDomains(state: IKnownDomainsState, knownDomains: Array<string>) {
|
2018-05-14 15:55:40 +00:00
|
|
|
// In case persistence has deserialized a weird redux state:
|
|
|
|
let nextState = Array.isArray(state) ? state : [];
|
|
|
|
|
|
|
|
if (Array.isArray(knownDomains)) {
|
|
|
|
nextState = Array.from(state);
|
|
|
|
for (let knownDomain of knownDomains) {
|
|
|
|
knownDomain = knownDomain.toLowerCase();
|
2018-05-29 12:51:55 +00:00
|
|
|
!nextState.includes(knownDomain) && nextState.push(knownDomain);
|
2018-05-14 15:55:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nextState;
|
|
|
|
}
|