2022-09-14 07:54:56 +00:00
|
|
|
/* eslint-disable lines-around-comment */
|
2019-11-12 13:37:54 +00:00
|
|
|
import _ from 'lodash';
|
2022-09-14 07:54:56 +00:00
|
|
|
import { AnyAction } from 'redux';
|
2017-12-14 17:02:32 +00:00
|
|
|
|
2022-09-14 07:54:56 +00:00
|
|
|
import { IStore } from '../../app/types';
|
2020-10-26 11:53:44 +00:00
|
|
|
import { PREJOIN_INITIALIZED } from '../../prejoin/actionTypes';
|
2021-12-20 09:34:40 +00:00
|
|
|
import { setPrejoinPageVisibility } from '../../prejoin/actions';
|
2022-09-14 07:54:56 +00:00
|
|
|
import { APP_WILL_MOUNT } from '../app/actionTypes';
|
|
|
|
import { setAudioOnly } from '../audio-only/actions';
|
2019-11-12 13:37:54 +00:00
|
|
|
import { SET_LOCATION_URL } from '../connection/actionTypes'; // minimize imports to avoid circular imports
|
2020-10-26 11:53:44 +00:00
|
|
|
import { getJwtName } from '../jwt/functions';
|
2022-09-14 07:54:56 +00:00
|
|
|
import { participantUpdated } from '../participants/actions';
|
|
|
|
import { getLocalParticipant } from '../participants/functions';
|
|
|
|
import MiddlewareRegistry from '../redux/MiddlewareRegistry';
|
|
|
|
import { parseURLParams } from '../util/parseURLParams';
|
2018-01-18 21:28:25 +00:00
|
|
|
|
2018-04-12 19:58:20 +00:00
|
|
|
import { SETTINGS_UPDATED } from './actionTypes';
|
2020-08-24 19:49:47 +00:00
|
|
|
import { updateSettings } from './actions';
|
2020-05-07 21:05:48 +00:00
|
|
|
import { handleCallIntegrationChange, handleCrashReportingChange } from './functions';
|
2022-09-14 07:54:56 +00:00
|
|
|
import { ISettingsState } from './reducer';
|
2017-12-14 17:02:32 +00:00
|
|
|
|
2021-01-21 20:46:47 +00:00
|
|
|
|
2017-12-14 17:02:32 +00:00
|
|
|
/**
|
2018-04-12 19:58:20 +00:00
|
|
|
* The middleware of the feature base/settings. Distributes changes to the state
|
|
|
|
* of base/settings to the states of other features computed from the state of
|
|
|
|
* base/settings.
|
2017-12-14 17:02:32 +00:00
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
|
|
|
const result = next(action);
|
|
|
|
|
|
|
|
switch (action.type) {
|
2019-11-08 10:52:21 +00:00
|
|
|
case APP_WILL_MOUNT:
|
|
|
|
_initializeCallIntegration(store);
|
2021-12-20 09:34:40 +00:00
|
|
|
_initializeShowPrejoin(store);
|
2019-11-08 10:52:21 +00:00
|
|
|
break;
|
2020-10-26 11:53:44 +00:00
|
|
|
case PREJOIN_INITIALIZED: {
|
|
|
|
_maybeUpdateDisplayName(store);
|
|
|
|
break;
|
|
|
|
}
|
2018-04-12 19:58:20 +00:00
|
|
|
case SETTINGS_UPDATED:
|
2019-10-18 14:30:59 +00:00
|
|
|
_maybeHandleCallIntegrationChange(action);
|
2018-04-13 16:26:42 +00:00
|
|
|
_maybeSetAudioOnly(store, action);
|
2018-04-27 15:41:53 +00:00
|
|
|
_updateLocalParticipant(store, action);
|
2020-05-07 21:05:48 +00:00
|
|
|
_maybeCrashReportingChange(action);
|
2019-11-08 10:52:21 +00:00
|
|
|
break;
|
2019-11-12 13:37:54 +00:00
|
|
|
case SET_LOCATION_URL:
|
|
|
|
_updateLocalParticipantFromUrl(store);
|
|
|
|
break;
|
2017-12-14 17:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
|
2021-12-20 09:34:40 +00:00
|
|
|
/**
|
|
|
|
* Overwrites the showPrejoin flag based on cached used selection for showing prejoin screen.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-09-14 07:54:56 +00:00
|
|
|
function _initializeShowPrejoin({ dispatch, getState }: IStore) {
|
2021-12-20 09:34:40 +00:00
|
|
|
const { userSelectedSkipPrejoin } = getState()['features/base/settings'];
|
|
|
|
|
|
|
|
if (userSelectedSkipPrejoin) {
|
|
|
|
dispatch(setPrejoinPageVisibility(false));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-08 10:52:21 +00:00
|
|
|
/**
|
|
|
|
* Initializes the audio device handler based on the `disableCallIntegration` setting.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-09-14 07:54:56 +00:00
|
|
|
function _initializeCallIntegration({ getState }: IStore) {
|
2019-11-08 10:52:21 +00:00
|
|
|
const { disableCallIntegration } = getState()['features/base/settings'];
|
|
|
|
|
|
|
|
if (typeof disableCallIntegration === 'boolean') {
|
|
|
|
handleCallIntegrationChange(disableCallIntegration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-27 15:41:53 +00:00
|
|
|
/**
|
|
|
|
* Maps the settings field names to participant names where they don't match.
|
|
|
|
* Currently there is only one such field, but may be extended in the future.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {string} settingsField - The name of the settings field to map.
|
|
|
|
* @returns {string}
|
|
|
|
*/
|
2022-09-14 07:54:56 +00:00
|
|
|
function _mapSettingsFieldToParticipant(settingsField: string) {
|
2018-04-27 15:41:53 +00:00
|
|
|
switch (settingsField) {
|
|
|
|
case 'displayName':
|
|
|
|
return 'name';
|
|
|
|
}
|
|
|
|
|
|
|
|
return settingsField;
|
|
|
|
}
|
|
|
|
|
2019-10-18 14:30:59 +00:00
|
|
|
/**
|
2019-11-08 10:52:21 +00:00
|
|
|
* Handles a change in the `disableCallIntegration` setting.
|
2019-10-18 14:30:59 +00:00
|
|
|
*
|
|
|
|
* @param {Object} action - The redux action.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-09-14 07:54:56 +00:00
|
|
|
function _maybeHandleCallIntegrationChange({ settings: { disableCallIntegration } }: {
|
|
|
|
settings: Partial<ISettingsState>;
|
|
|
|
}) {
|
2019-10-18 14:30:59 +00:00
|
|
|
if (typeof disableCallIntegration === 'boolean') {
|
|
|
|
handleCallIntegrationChange(disableCallIntegration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-07 21:05:48 +00:00
|
|
|
/**
|
|
|
|
* Handles a change in the `disableCrashReporting` setting.
|
|
|
|
*
|
|
|
|
* @param {Object} action - The redux action.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-09-14 07:54:56 +00:00
|
|
|
function _maybeCrashReportingChange({ settings: { disableCrashReporting } }: {
|
|
|
|
settings: Partial<ISettingsState>;
|
|
|
|
}) {
|
2020-05-07 21:05:48 +00:00
|
|
|
if (typeof disableCrashReporting === 'boolean') {
|
|
|
|
handleCrashReportingChange(disableCrashReporting);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-02 14:50:16 +00:00
|
|
|
/**
|
2018-04-12 19:58:20 +00:00
|
|
|
* Updates {@code startAudioOnly} flag if it's updated in the settings.
|
2018-02-02 14:50:16 +00:00
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @param {Object} action - The redux action.
|
2018-04-13 16:26:42 +00:00
|
|
|
* @private
|
2018-02-02 14:50:16 +00:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2018-04-13 16:26:42 +00:00
|
|
|
function _maybeSetAudioOnly(
|
2022-09-14 07:54:56 +00:00
|
|
|
{ dispatch }: IStore,
|
|
|
|
{ settings: { startAudioOnly } }: { settings: Partial<ISettingsState>; }) {
|
2018-02-27 20:21:28 +00:00
|
|
|
if (typeof startAudioOnly === 'boolean') {
|
2021-11-23 10:56:29 +00:00
|
|
|
dispatch(setAudioOnly(startAudioOnly));
|
2018-02-02 14:50:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-26 11:53:44 +00:00
|
|
|
/**
|
|
|
|
* Updates the display name to the one in JWT if there is one.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-09-14 07:54:56 +00:00
|
|
|
function _maybeUpdateDisplayName({ dispatch, getState }: IStore) {
|
2020-10-26 11:53:44 +00:00
|
|
|
const state = getState();
|
|
|
|
const hasJwt = Boolean(state['features/base/jwt'].jwt);
|
|
|
|
|
|
|
|
if (hasJwt) {
|
|
|
|
const displayName = getJwtName(state);
|
|
|
|
|
2021-03-10 19:36:32 +00:00
|
|
|
if (displayName) {
|
|
|
|
dispatch(updateSettings({
|
|
|
|
displayName
|
|
|
|
}));
|
|
|
|
}
|
2020-10-26 11:53:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-14 17:02:32 +00:00
|
|
|
/**
|
2018-04-12 19:58:20 +00:00
|
|
|
* Updates the local participant according to settings changes.
|
2017-12-14 17:02:32 +00:00
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
2018-04-27 15:41:53 +00:00
|
|
|
* @param {Object} action - The dispatched action.
|
2018-04-13 16:26:42 +00:00
|
|
|
* @private
|
2017-12-14 17:02:32 +00:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-09-14 07:54:56 +00:00
|
|
|
function _updateLocalParticipant({ dispatch, getState }: IStore, action: AnyAction) {
|
2018-04-27 15:41:53 +00:00
|
|
|
const { settings } = action;
|
|
|
|
const localParticipant = getLocalParticipant(getState());
|
|
|
|
const newLocalParticipant = {
|
|
|
|
...localParticipant
|
|
|
|
};
|
2017-12-14 17:02:32 +00:00
|
|
|
|
2018-04-27 15:41:53 +00:00
|
|
|
for (const key in settings) {
|
|
|
|
if (settings.hasOwnProperty(key)) {
|
2022-09-14 07:54:56 +00:00
|
|
|
newLocalParticipant[_mapSettingsFieldToParticipant(key) as keyof typeof newLocalParticipant]
|
2018-04-27 15:41:53 +00:00
|
|
|
= settings[key];
|
|
|
|
}
|
|
|
|
}
|
2017-12-14 17:02:32 +00:00
|
|
|
|
2022-09-14 07:54:56 +00:00
|
|
|
dispatch(participantUpdated({
|
|
|
|
...newLocalParticipant,
|
|
|
|
id: newLocalParticipant.id ?? ''
|
|
|
|
}));
|
2017-12-14 17:02:32 +00:00
|
|
|
}
|
2019-11-12 13:37:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the userInfo set in the URL.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-09-14 07:54:56 +00:00
|
|
|
function _updateLocalParticipantFromUrl({ dispatch, getState }: IStore) {
|
2019-11-12 13:37:54 +00:00
|
|
|
const urlParams
|
2022-09-14 07:54:56 +00:00
|
|
|
= parseURLParams(getState()['features/base/connection'].locationURL ?? '');
|
2019-11-12 13:37:54 +00:00
|
|
|
const urlEmail = urlParams['userInfo.email'];
|
2020-04-09 13:26:19 +00:00
|
|
|
const urlDisplayName = urlParams['userInfo.displayName'];
|
2019-11-12 13:37:54 +00:00
|
|
|
|
2020-04-09 13:26:19 +00:00
|
|
|
if (!urlEmail && !urlDisplayName) {
|
2019-11-12 13:37:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const localParticipant = getLocalParticipant(getState());
|
|
|
|
|
|
|
|
if (localParticipant) {
|
2020-08-24 19:49:47 +00:00
|
|
|
const displayName = _.escape(urlDisplayName);
|
|
|
|
const email = _.escape(urlEmail);
|
|
|
|
|
2019-11-12 13:37:54 +00:00
|
|
|
dispatch(participantUpdated({
|
|
|
|
...localParticipant,
|
2020-08-24 19:49:47 +00:00
|
|
|
email,
|
|
|
|
name: displayName
|
|
|
|
}));
|
|
|
|
|
|
|
|
dispatch(updateSettings({
|
|
|
|
displayName,
|
|
|
|
email
|
2019-11-12 13:37:54 +00:00
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|