Fix accidental overwrite of localParticipant with empty values

This commit is contained in:
zbettenbuk 2018-04-27 17:41:53 +02:00 committed by Saúl Ibarra Corretgé
parent 959db3a665
commit cc7e15ab8f
1 changed files with 33 additions and 15 deletions

View File

@ -2,10 +2,9 @@
import { setAudioOnly } from '../conference'; import { setAudioOnly } from '../conference';
import { getLocalParticipant, participantUpdated } from '../participants'; import { getLocalParticipant, participantUpdated } from '../participants';
import { MiddlewareRegistry, toState } from '../redux'; import { MiddlewareRegistry } from '../redux';
import { SETTINGS_UPDATED } from './actionTypes'; import { SETTINGS_UPDATED } from './actionTypes';
import { getSettings } from './functions';
/** /**
* The middleware of the feature base/settings. Distributes changes to the state * The middleware of the feature base/settings. Distributes changes to the state
@ -21,12 +20,29 @@ MiddlewareRegistry.register(store => next => action => {
switch (action.type) { switch (action.type) {
case SETTINGS_UPDATED: case SETTINGS_UPDATED:
_maybeSetAudioOnly(store, action); _maybeSetAudioOnly(store, action);
_updateLocalParticipant(store); _updateLocalParticipant(store, action);
} }
return result; return result;
}); });
/**
* 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;
}
/** /**
* Updates {@code startAudioOnly} flag if it's updated in the settings. * Updates {@code startAudioOnly} flag if it's updated in the settings.
* *
@ -47,21 +63,23 @@ function _maybeSetAudioOnly(
* Updates the local participant according to settings changes. * Updates the local participant according to settings changes.
* *
* @param {Store} store - The redux store. * @param {Store} store - The redux store.
* @param {Object} action - The dispatched action.
* @private * @private
* @returns {void} * @returns {void}
*/ */
function _updateLocalParticipant(store) { function _updateLocalParticipant({ dispatch, getState }, action) {
const state = toState(store); const { settings } = action;
const localParticipant = getLocalParticipant(state); const localParticipant = getLocalParticipant(getState());
const settings = getSettings(state); const newLocalParticipant = {
...localParticipant
};
store.dispatch(participantUpdated({ for (const key in settings) {
// Identify that the participant to update i.e. the local participant: if (settings.hasOwnProperty(key)) {
id: localParticipant && localParticipant.id, newLocalParticipant[_mapSettingsFieldToParticipant(key)]
local: true, = settings[key];
}
}
// Specify the updates to be applied to the identified participant: dispatch(participantUpdated(newLocalParticipant));
email: settings.email,
name: settings.displayName
}));
} }