2017-10-09 15:03:02 +00:00
|
|
|
// @flow
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
import {
|
|
|
|
DOMINANT_SPEAKER_CHANGED,
|
|
|
|
PARTICIPANT_JOINED,
|
|
|
|
PARTICIPANT_LEFT,
|
2018-05-11 17:34:39 +00:00
|
|
|
PIN_PARTICIPANT,
|
2022-09-08 21:14:00 +00:00
|
|
|
getLocalParticipant,
|
|
|
|
getDominantSpeakerParticipant
|
2016-10-05 14:36:59 +00:00
|
|
|
} from '../base/participants';
|
|
|
|
import { MiddlewareRegistry } from '../base/redux';
|
2020-09-09 21:14:53 +00:00
|
|
|
import { isTestModeEnabled } from '../base/testing';
|
2016-10-05 14:36:59 +00:00
|
|
|
import {
|
|
|
|
TRACK_ADDED,
|
2021-05-19 23:23:40 +00:00
|
|
|
TRACK_REMOVED
|
2016-10-05 14:36:59 +00:00
|
|
|
} from '../base/tracks';
|
2021-12-01 14:00:38 +00:00
|
|
|
import { TOGGLE_DOCUMENT_EDITING } from '../etherpad/actionTypes';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2021-05-19 23:23:40 +00:00
|
|
|
import { selectParticipantInLargeVideo } from './actions';
|
2020-09-09 21:14:53 +00:00
|
|
|
import logger from './logger';
|
2016-10-05 14:36:59 +00:00
|
|
|
|
2020-06-04 14:09:13 +00:00
|
|
|
import './subscriber';
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
/**
|
|
|
|
* Middleware that catches actions related to participants and tracks and
|
|
|
|
* dispatches an action to select a participant depicted by LargeVideo.
|
|
|
|
*
|
|
|
|
* @param {Store} store - Redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
|
|
|
switch (action.type) {
|
2018-05-11 17:34:39 +00:00
|
|
|
case DOMINANT_SPEAKER_CHANGED: {
|
2020-09-09 21:14:53 +00:00
|
|
|
const state = store.getState();
|
|
|
|
const localParticipant = getLocalParticipant(state);
|
2022-09-08 21:14:00 +00:00
|
|
|
const dominantSpeaker = getDominantSpeakerParticipant(state);
|
|
|
|
|
|
|
|
|
|
|
|
if (dominantSpeaker?.id === action.participant.id) {
|
|
|
|
return next(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
const result = next(action);
|
2020-09-09 21:14:53 +00:00
|
|
|
|
|
|
|
if (isTestModeEnabled(state)) {
|
|
|
|
logger.info(`Dominant speaker changed event for: ${action.participant.id}`);
|
|
|
|
}
|
2018-05-11 17:34:39 +00:00
|
|
|
|
|
|
|
if (localParticipant && localParticipant.id !== action.participant.id) {
|
|
|
|
store.dispatch(selectParticipantInLargeVideo());
|
|
|
|
}
|
|
|
|
|
2022-09-08 21:14:00 +00:00
|
|
|
return result;
|
2018-05-11 17:34:39 +00:00
|
|
|
}
|
2016-10-05 14:36:59 +00:00
|
|
|
case PARTICIPANT_JOINED:
|
|
|
|
case PARTICIPANT_LEFT:
|
|
|
|
case PIN_PARTICIPANT:
|
2021-12-01 14:00:38 +00:00
|
|
|
case TOGGLE_DOCUMENT_EDITING:
|
2016-10-05 14:36:59 +00:00
|
|
|
case TRACK_ADDED:
|
2022-09-08 21:14:00 +00:00
|
|
|
case TRACK_REMOVED: {
|
|
|
|
const result = next(action);
|
|
|
|
|
2016-10-05 14:36:59 +00:00
|
|
|
store.dispatch(selectParticipantInLargeVideo());
|
2022-09-08 21:14:00 +00:00
|
|
|
|
|
|
|
return result;
|
2016-10-05 14:36:59 +00:00
|
|
|
}
|
2022-09-08 21:14:00 +00:00
|
|
|
}
|
|
|
|
const result = next(action);
|
2016-10-05 14:36:59 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
});
|