2022-09-14 07:54:56 +00:00
|
|
|
// @ts-ignore
|
2020-07-09 07:17:23 +00:00
|
|
|
import { jitsiLocalStorage } from '@jitsi/js-utils';
|
2017-04-23 20:14:02 +00:00
|
|
|
|
2022-10-11 10:47:54 +00:00
|
|
|
import { IStore } from '../../app/types';
|
2022-09-14 07:54:56 +00:00
|
|
|
import { addKnownDomains } from '../known-domains/actions';
|
|
|
|
import { parseURIString } from '../util/uri';
|
2018-05-14 20:49:00 +00:00
|
|
|
|
2021-03-10 15:39:35 +00:00
|
|
|
import {
|
|
|
|
CONFIG_WILL_LOAD,
|
|
|
|
LOAD_CONFIG_ERROR,
|
2022-09-27 07:10:28 +00:00
|
|
|
OVERWRITE_CONFIG,
|
2021-03-10 15:39:35 +00:00
|
|
|
SET_CONFIG,
|
2022-09-27 07:10:28 +00:00
|
|
|
UPDATE_CONFIG
|
2021-03-10 15:39:35 +00:00
|
|
|
} from './actionTypes';
|
2022-09-14 07:54:56 +00:00
|
|
|
import { IConfig } from './configType';
|
2018-05-14 20:49:00 +00:00
|
|
|
import { _CONFIG_STORE_PREFIX } from './constants';
|
2022-09-14 07:54:56 +00:00
|
|
|
import { setConfigFromURLParams } from './functions.any';
|
2017-11-29 14:15:57 +00:00
|
|
|
|
2020-08-14 07:45:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates the config with new options.
|
|
|
|
*
|
|
|
|
* @param {Object} config - The new options (to add).
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
2022-09-14 07:54:56 +00:00
|
|
|
export function updateConfig(config: IConfig) {
|
2020-08-14 07:45:15 +00:00
|
|
|
return {
|
|
|
|
type: UPDATE_CONFIG,
|
|
|
|
config
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-11-29 14:15:57 +00:00
|
|
|
/**
|
2018-05-23 21:10:04 +00:00
|
|
|
* Signals that the configuration (commonly known in Jitsi Meet as config.js)
|
|
|
|
* for a specific locationURL will be loaded now.
|
2017-11-29 14:15:57 +00:00
|
|
|
*
|
2018-05-23 21:10:04 +00:00
|
|
|
* @param {URL} locationURL - The URL of the location which necessitated the
|
|
|
|
* loading of a configuration.
|
2019-04-09 15:53:12 +00:00
|
|
|
* @param {string} room - The name of the room (conference) for which we're loading the config for.
|
2017-11-29 14:15:57 +00:00
|
|
|
* @returns {{
|
|
|
|
* type: CONFIG_WILL_LOAD,
|
2019-04-09 15:53:12 +00:00
|
|
|
* locationURL: URL,
|
|
|
|
* room: string
|
2017-11-29 14:15:57 +00:00
|
|
|
* }}
|
|
|
|
*/
|
2019-04-09 15:53:12 +00:00
|
|
|
export function configWillLoad(locationURL: URL, room: string) {
|
2017-11-29 14:15:57 +00:00
|
|
|
return {
|
|
|
|
type: CONFIG_WILL_LOAD,
|
2019-04-09 15:53:12 +00:00
|
|
|
locationURL,
|
|
|
|
room
|
2017-11-29 14:15:57 +00:00
|
|
|
};
|
|
|
|
}
|
2017-08-25 15:21:01 +00:00
|
|
|
|
|
|
|
/**
|
2018-05-23 21:10:04 +00:00
|
|
|
* Signals that a configuration (commonly known in Jitsi Meet as config.js)
|
|
|
|
* could not be loaded due to a specific error.
|
2017-08-25 15:21:01 +00:00
|
|
|
*
|
2017-09-06 23:26:33 +00:00
|
|
|
* @param {Error} error - The {@code Error} which prevented the successful
|
|
|
|
* loading of a configuration.
|
2018-05-23 21:10:04 +00:00
|
|
|
* @param {URL} locationURL - The URL of the location which necessitated the
|
|
|
|
* loading of a configuration.
|
2017-08-25 15:21:01 +00:00
|
|
|
* @returns {{
|
2017-09-06 23:26:33 +00:00
|
|
|
* type: LOAD_CONFIG_ERROR,
|
|
|
|
* error: Error,
|
2018-05-23 21:10:04 +00:00
|
|
|
* locationURL: URL
|
2017-08-25 15:21:01 +00:00
|
|
|
* }}
|
|
|
|
*/
|
2018-05-23 21:10:04 +00:00
|
|
|
export function loadConfigError(error: Error, locationURL: URL) {
|
2017-08-25 15:21:01 +00:00
|
|
|
return {
|
|
|
|
type: LOAD_CONFIG_ERROR,
|
2017-09-06 23:26:33 +00:00
|
|
|
error,
|
|
|
|
locationURL
|
2017-08-25 15:21:01 +00:00
|
|
|
};
|
|
|
|
}
|
2017-04-23 20:14:02 +00:00
|
|
|
|
2021-03-10 15:39:35 +00:00
|
|
|
/**
|
|
|
|
* Overwrites some config values.
|
|
|
|
*
|
|
|
|
* @param {Object} config - The new options (to overwrite).
|
|
|
|
* @returns {{
|
|
|
|
* type: OVERWRITE_CONFIG,
|
|
|
|
* config: Object
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function overwriteConfig(config: Object) {
|
|
|
|
return {
|
|
|
|
type: OVERWRITE_CONFIG,
|
|
|
|
config
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-04-23 20:14:02 +00:00
|
|
|
/**
|
|
|
|
* Sets the configuration represented by the feature base/config. The
|
|
|
|
* configuration is defined and consumed by the library lib-jitsi-meet but some
|
|
|
|
* of its properties are consumed by the application jitsi-meet as well.
|
|
|
|
*
|
|
|
|
* @param {Object} config - The configuration to be represented by the feature
|
|
|
|
* base/config.
|
2018-03-06 16:08:23 +00:00
|
|
|
* @returns {Function}
|
2017-04-23 20:14:02 +00:00
|
|
|
*/
|
2017-08-25 12:51:57 +00:00
|
|
|
export function setConfig(config: Object = {}) {
|
2022-10-11 10:47:54 +00:00
|
|
|
return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
|
2018-03-06 16:08:23 +00:00
|
|
|
const { locationURL } = getState()['features/base/connection'];
|
|
|
|
|
|
|
|
// Now that the loading of the config was successful override the values
|
|
|
|
// with the parameters passed in the hash part of the location URI.
|
|
|
|
// TODO We're still in the middle ground between old Web with config,
|
2022-08-17 12:32:40 +00:00
|
|
|
// and interfaceConfig used via global variables and new
|
2018-03-06 16:08:23 +00:00
|
|
|
// Web and mobile reading the respective values from the redux store.
|
|
|
|
// Only the config will be overridden on React Native, as the other
|
|
|
|
// globals will be undefined here. It's intentional - we do not care to
|
|
|
|
// override those configs yet.
|
|
|
|
locationURL
|
|
|
|
&& setConfigFromURLParams(
|
|
|
|
|
|
|
|
// On Web the config also comes from the window.config global,
|
|
|
|
// but it is resolved in the loadConfig procedure.
|
|
|
|
config,
|
|
|
|
window.interfaceConfig,
|
|
|
|
locationURL);
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
type: SET_CONFIG,
|
|
|
|
config
|
|
|
|
});
|
2017-04-23 20:14:02 +00:00
|
|
|
};
|
|
|
|
}
|
2018-05-14 20:49:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores a specific Jitsi Meet config.js object into {@code localStorage}.
|
|
|
|
*
|
|
|
|
* @param {string} baseURL - The base URL from which the config.js was
|
|
|
|
* downloaded.
|
|
|
|
* @param {Object} config - The Jitsi Meet config.js to store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
export function storeConfig(baseURL: string, config: Object) {
|
2022-10-11 10:47:54 +00:00
|
|
|
return (dispatch: IStore['dispatch']) => {
|
2018-05-14 20:49:00 +00:00
|
|
|
// Try to store the configuration in localStorage. If the deployment
|
|
|
|
// specified 'getroom' as a function, for example, it does not make
|
|
|
|
// sense to and it will not be stored.
|
|
|
|
let b = false;
|
|
|
|
|
|
|
|
try {
|
2020-05-01 19:48:08 +00:00
|
|
|
if (typeof window.config === 'undefined' || window.config !== config) {
|
|
|
|
jitsiLocalStorage.setItem(`${_CONFIG_STORE_PREFIX}/${baseURL}`, JSON.stringify(config));
|
2018-05-14 20:49:00 +00:00
|
|
|
b = true;
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
// Ignore the error because the caching is optional.
|
|
|
|
}
|
|
|
|
|
|
|
|
// If base/config knows a domain, then the app knows it.
|
|
|
|
if (b) {
|
|
|
|
try {
|
2022-09-14 07:54:56 +00:00
|
|
|
dispatch(addKnownDomains(parseURIString(baseURL)?.host));
|
2018-05-14 20:49:00 +00:00
|
|
|
} catch (e) {
|
|
|
|
// Ignore the error because the fiddling with "known domains" is
|
|
|
|
// a side effect here.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return b;
|
|
|
|
};
|
|
|
|
}
|