2017-10-02 23:08:07 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2017-06-29 03:35:43 +00:00
|
|
|
import UIEvents from '../../../../service/UI/UIEvents';
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
import {
|
|
|
|
CONFERENCE_JOINED,
|
|
|
|
CONFERENCE_LEFT
|
|
|
|
} from '../conference';
|
|
|
|
import { MiddlewareRegistry } from '../redux';
|
|
|
|
|
|
|
|
import { localParticipantIdChanged } from './actions';
|
2017-08-14 15:02:58 +00:00
|
|
|
import {
|
|
|
|
KICK_PARTICIPANT,
|
|
|
|
MUTE_REMOTE_PARTICIPANT,
|
|
|
|
PARTICIPANT_DISPLAY_NAME_CHANGED
|
|
|
|
} from './actionTypes';
|
2016-10-05 14:36:59 +00:00
|
|
|
import { LOCAL_PARTICIPANT_DEFAULT_ID } from './constants';
|
2017-06-29 03:35:43 +00:00
|
|
|
import { getLocalParticipant } from './functions';
|
|
|
|
|
|
|
|
declare var APP: Object;
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Middleware that captures CONFERENCE_JOINED and CONFERENCE_LEFT actions and
|
|
|
|
* updates respectively ID of local participant.
|
|
|
|
*
|
|
|
|
* @param {Store} store - Redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
2017-11-09 17:23:17 +00:00
|
|
|
const { conference } = store.getState()['features/base/conference'];
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case CONFERENCE_JOINED:
|
2016-12-12 00:29:13 +00:00
|
|
|
store.dispatch(localParticipantIdChanged(action.conference.myUserId()));
|
2016-10-05 14:36:59 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONFERENCE_LEFT:
|
|
|
|
store.dispatch(localParticipantIdChanged(LOCAL_PARTICIPANT_DEFAULT_ID));
|
|
|
|
break;
|
2017-06-29 03:35:43 +00:00
|
|
|
|
2017-08-14 15:02:58 +00:00
|
|
|
case KICK_PARTICIPANT:
|
2017-11-09 17:23:17 +00:00
|
|
|
conference.kickParticipant(action.id);
|
2017-08-14 15:02:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case MUTE_REMOTE_PARTICIPANT:
|
2017-11-09 17:23:17 +00:00
|
|
|
conference.muteParticipant(action.id);
|
2017-08-14 15:02:58 +00:00
|
|
|
break;
|
|
|
|
|
2017-06-29 03:35:43 +00:00
|
|
|
// TODO Remove this middleware when the local display name update flow is
|
|
|
|
// fully brought into redux.
|
|
|
|
case PARTICIPANT_DISPLAY_NAME_CHANGED: {
|
|
|
|
if (typeof APP !== 'undefined') {
|
|
|
|
const participant = getLocalParticipant(store.getState());
|
|
|
|
|
|
|
|
if (participant && participant.id === action.id) {
|
|
|
|
APP.UI.emitEvent(UIEvents.NICKNAME_CHANGED, action.name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
});
|