2018-03-09 14:52:59 +00:00
|
|
|
// @flow
|
|
|
|
|
2020-07-09 07:17:23 +00:00
|
|
|
import { jitsiLocalStorage } from '@jitsi/js-utils';
|
2020-05-01 19:48:08 +00:00
|
|
|
|
2018-07-11 09:42:43 +00:00
|
|
|
import { APP_WILL_MOUNT } from '../app';
|
2020-07-07 20:34:52 +00:00
|
|
|
import { getFeatureFlag } from '../flags/functions';
|
2018-05-14 20:49:00 +00:00
|
|
|
import { addKnownDomains } from '../known-domains';
|
2018-03-09 14:52:59 +00:00
|
|
|
import { MiddlewareRegistry } from '../redux';
|
2018-05-14 20:49:00 +00:00
|
|
|
import { parseURIString } from '../util';
|
2018-03-09 14:52:59 +00:00
|
|
|
|
2020-08-14 07:45:15 +00:00
|
|
|
import { SET_CONFIG } from './actionTypes';
|
|
|
|
import { updateConfig } from './actions';
|
2018-05-14 20:49:00 +00:00
|
|
|
import { _CONFIG_STORE_PREFIX } from './constants';
|
2018-03-09 14:52:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The middleware of the feature {@code base/config}.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @private
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
|
|
|
switch (action.type) {
|
2018-05-14 20:49:00 +00:00
|
|
|
case APP_WILL_MOUNT:
|
|
|
|
return _appWillMount(store, next, action);
|
|
|
|
|
2018-03-09 14:52:59 +00:00
|
|
|
case SET_CONFIG:
|
|
|
|
return _setConfig(store, next, action);
|
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
});
|
|
|
|
|
2018-05-14 20:49:00 +00:00
|
|
|
/**
|
|
|
|
* Notifies the feature {@code base/config} that the {@link APP_WILL_MOUNT}
|
|
|
|
* redux action is being {@code dispatch}ed in a specific redux store.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store in which the specified {@code action}
|
|
|
|
* is being dispatched.
|
|
|
|
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
|
|
|
* specified {@code action} in the specified {@code store}.
|
|
|
|
* @param {Action} action - The redux action which is being {@code dispatch}ed
|
|
|
|
* in the specified {@code store}.
|
|
|
|
* @private
|
|
|
|
* @returns {*} The return value of {@code next(action)}.
|
|
|
|
*/
|
|
|
|
function _appWillMount(store, next, action) {
|
|
|
|
const result = next(action);
|
|
|
|
|
|
|
|
// It's an opportune time to transfer the feature base/config's knowledge
|
|
|
|
// about "known domains" (which is local to the feature) to the feature
|
|
|
|
// base/known-domains (which is global to the app).
|
|
|
|
//
|
|
|
|
// XXX Since the feature base/config predates the feature calendar-sync and,
|
|
|
|
// consequently, the feature known-domains, it's possible for the feature
|
|
|
|
// base/config to know of domains which the feature known-domains is yet to
|
|
|
|
// discover.
|
|
|
|
|
2020-05-01 19:48:08 +00:00
|
|
|
const prefix = `${_CONFIG_STORE_PREFIX}/`;
|
|
|
|
const knownDomains = [];
|
2018-05-14 20:49:00 +00:00
|
|
|
|
2020-05-01 19:48:08 +00:00
|
|
|
for (let i = 0; /* localStorage.key(i) */; ++i) {
|
|
|
|
const key = jitsiLocalStorage.key(i);
|
2018-05-14 20:49:00 +00:00
|
|
|
|
2020-05-01 19:48:08 +00:00
|
|
|
if (key) {
|
|
|
|
let baseURL;
|
2018-05-14 20:49:00 +00:00
|
|
|
|
2020-05-01 19:48:08 +00:00
|
|
|
if (key.startsWith(prefix)
|
|
|
|
&& (baseURL = key.substring(prefix.length))) {
|
|
|
|
const uri = parseURIString(baseURL);
|
|
|
|
let host;
|
2018-05-14 20:49:00 +00:00
|
|
|
|
2020-05-01 19:48:08 +00:00
|
|
|
uri && (host = uri.host) && knownDomains.push(host);
|
2018-05-14 20:49:00 +00:00
|
|
|
}
|
2020-05-01 19:48:08 +00:00
|
|
|
} else {
|
|
|
|
break;
|
2018-05-14 20:49:00 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-01 19:48:08 +00:00
|
|
|
knownDomains.length && store.dispatch(addKnownDomains(knownDomains));
|
2018-05-14 20:49:00 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-03-09 14:52:59 +00:00
|
|
|
/**
|
|
|
|
* Notifies the feature {@code base/config} that the {@link SET_CONFIG} redux
|
|
|
|
* action is being {@code dispatch}ed in a specific redux store.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store in which the specified {@code action}
|
|
|
|
* is being dispatched.
|
|
|
|
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
|
|
|
* specified {@code action} in the specified {@code store}.
|
|
|
|
* @param {Action} action - The redux action which is being {@code dispatch}ed
|
|
|
|
* in the specified {@code store}.
|
|
|
|
* @private
|
|
|
|
* @returns {*} The return value of {@code next(action)}.
|
|
|
|
*/
|
2019-10-18 14:30:59 +00:00
|
|
|
function _setConfig({ dispatch, getState }, next, action) {
|
2018-03-09 14:52:59 +00:00
|
|
|
// The reducer is doing some alterations to the config passed in the action,
|
|
|
|
// so make sure it's the final state by waiting for the action to be
|
|
|
|
// reduced.
|
|
|
|
const result = next(action);
|
2019-10-18 14:30:59 +00:00
|
|
|
const state = getState();
|
|
|
|
|
|
|
|
// Update the config with user defined settings.
|
|
|
|
const settings = state['features/base/settings'];
|
|
|
|
const config = {};
|
|
|
|
|
|
|
|
if (typeof settings.disableP2P !== 'undefined') {
|
|
|
|
config.p2p = { enabled: !settings.disableP2P };
|
|
|
|
}
|
|
|
|
|
2020-07-07 20:34:52 +00:00
|
|
|
const resolutionFlag = getFeatureFlag(state, 'resolution');
|
|
|
|
|
|
|
|
if (typeof resolutionFlag !== 'undefined') {
|
|
|
|
config.resolution = resolutionFlag;
|
|
|
|
}
|
|
|
|
|
2020-08-14 07:45:15 +00:00
|
|
|
dispatch(updateConfig(config));
|
2018-03-09 14:52:59 +00:00
|
|
|
|
|
|
|
// FIXME On Web we rely on the global 'config' variable which gets altered
|
|
|
|
// multiple times, before it makes it to the reducer. At some point it may
|
|
|
|
// not be the global variable which is being modified anymore due to
|
|
|
|
// different merge methods being used along the way. The global variable
|
|
|
|
// must be synchronized with the final state resolved by the reducer.
|
|
|
|
if (typeof window.config !== 'undefined') {
|
2019-10-18 14:30:59 +00:00
|
|
|
window.config = state['features/base/config'];
|
2018-03-09 14:52:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|