2018-01-18 21:28:25 +00:00
|
|
|
// @flow
|
2019-11-12 13:37:54 +00:00
|
|
|
import _ from 'lodash';
|
2017-12-14 17:02:32 +00:00
|
|
|
|
2020-10-26 11:53:44 +00:00
|
|
|
import { PREJOIN_INITIALIZED } from '../../prejoin/actionTypes';
|
2019-11-08 10:52:21 +00:00
|
|
|
import { APP_WILL_MOUNT } from '../app';
|
2019-07-31 12:47:52 +00:00
|
|
|
import { setAudioOnly } from '../audio-only';
|
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';
|
2018-01-18 21:28:25 +00:00
|
|
|
import { getLocalParticipant, participantUpdated } from '../participants';
|
2018-04-27 15:41:53 +00:00
|
|
|
import { MiddlewareRegistry } from '../redux';
|
2020-05-20 10:57:03 +00:00
|
|
|
import { parseURLParams } from '../util';
|
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';
|
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);
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
|
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}
|
|
|
|
*/
|
|
|
|
function _initializeCallIntegration({ getState }) {
|
|
|
|
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}
|
|
|
|
*/
|
|
|
|
function _mapSettingsFieldToParticipant(settingsField) {
|
|
|
|
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}
|
|
|
|
*/
|
|
|
|
function _maybeHandleCallIntegrationChange({ settings: { disableCallIntegration } }) {
|
|
|
|
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}
|
|
|
|
*/
|
|
|
|
function _maybeCrashReportingChange({ settings: { disableCrashReporting } }) {
|
|
|
|
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(
|
2018-02-27 20:21:28 +00:00
|
|
|
{ dispatch },
|
2018-04-12 19:58:20 +00:00
|
|
|
{ settings: { startAudioOnly } }) {
|
2018-02-27 20:21:28 +00:00
|
|
|
if (typeof startAudioOnly === 'boolean') {
|
2018-06-18 15:19:59 +00:00
|
|
|
dispatch(setAudioOnly(startAudioOnly, true));
|
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}
|
|
|
|
*/
|
|
|
|
function _maybeUpdateDisplayName({ dispatch, getState }) {
|
|
|
|
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}
|
|
|
|
*/
|
2018-04-27 15:41:53 +00:00
|
|
|
function _updateLocalParticipant({ dispatch, getState }, action) {
|
|
|
|
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)) {
|
|
|
|
newLocalParticipant[_mapSettingsFieldToParticipant(key)]
|
|
|
|
= settings[key];
|
|
|
|
}
|
|
|
|
}
|
2017-12-14 17:02:32 +00:00
|
|
|
|
2018-04-27 15:41:53 +00:00
|
|
|
dispatch(participantUpdated(newLocalParticipant));
|
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}
|
|
|
|
*/
|
|
|
|
function _updateLocalParticipantFromUrl({ dispatch, getState }) {
|
|
|
|
const urlParams
|
|
|
|
= parseURLParams(getState()['features/base/connection'].locationURL);
|
|
|
|
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
|
|
|
}));
|
|
|
|
}
|
|
|
|
}
|