2018-01-18 21:28:25 +00:00
|
|
|
// @flow
|
2017-12-14 17:02:32 +00:00
|
|
|
|
2018-02-02 14:50:16 +00:00
|
|
|
import { setAudioOnly } from '../conference';
|
2018-01-18 21:28:25 +00:00
|
|
|
import { getLocalParticipant, participantUpdated } from '../participants';
|
|
|
|
import { MiddlewareRegistry, toState } from '../redux';
|
|
|
|
|
|
|
|
import { PROFILE_UPDATED } from './actionTypes';
|
2017-12-14 17:02:32 +00:00
|
|
|
|
|
|
|
/**
|
2018-04-13 16:26:42 +00:00
|
|
|
* The middleware of the feature base/profile. Distributes changes to the state
|
|
|
|
* of base/profile to the states of other features computed from the state of
|
|
|
|
* base/profile.
|
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) {
|
|
|
|
case PROFILE_UPDATED:
|
|
|
|
_updateLocalParticipant(store);
|
2018-04-13 16:26:42 +00:00
|
|
|
_maybeSetAudioOnly(store, action);
|
2017-12-14 17:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
});
|
|
|
|
|
2018-02-02 14:50:16 +00:00
|
|
|
/**
|
2018-04-13 16:26:42 +00:00
|
|
|
* Updates {@code startAudioOnly} flag if it's updated in the profile.
|
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 },
|
|
|
|
{ profile: { startAudioOnly } }) {
|
|
|
|
if (typeof startAudioOnly === 'boolean') {
|
|
|
|
dispatch(setAudioOnly(startAudioOnly));
|
2018-02-02 14:50:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-14 17:02:32 +00:00
|
|
|
/**
|
|
|
|
* Updates the local participant according to profile changes.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
2018-04-13 16:26:42 +00:00
|
|
|
* @private
|
2017-12-14 17:02:32 +00:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function _updateLocalParticipant(store) {
|
2018-01-18 21:28:25 +00:00
|
|
|
const state = toState(store);
|
|
|
|
const localParticipant = getLocalParticipant(state);
|
2018-02-27 20:21:28 +00:00
|
|
|
const profile = state['features/base/profile'];
|
2017-12-14 17:02:32 +00:00
|
|
|
|
2018-01-18 21:28:25 +00:00
|
|
|
store.dispatch(participantUpdated({
|
|
|
|
// Identify that the participant to update i.e. the local participant:
|
|
|
|
id: localParticipant && localParticipant.id,
|
|
|
|
local: true,
|
2017-12-14 17:02:32 +00:00
|
|
|
|
2018-01-18 21:28:25 +00:00
|
|
|
// Specify the updates to be applied to the identified participant:
|
|
|
|
email: profile.email,
|
|
|
|
name: profile.displayName
|
|
|
|
}));
|
2017-12-14 17:02:32 +00:00
|
|
|
}
|