2020-01-24 16:28:47 +00:00
|
|
|
// @flow
|
|
|
|
|
2021-01-21 20:46:47 +00:00
|
|
|
import VideoLayout from '../../../modules/UI/videolayout/VideoLayout';
|
2021-08-18 22:34:01 +00:00
|
|
|
import { PARTICIPANT_JOINED, PARTICIPANT_LEFT } from '../base/participants';
|
2020-01-24 16:28:47 +00:00
|
|
|
import { MiddlewareRegistry } from '../base/redux';
|
|
|
|
import { CLIENT_RESIZED } from '../base/responsive-ui';
|
2021-01-21 20:46:47 +00:00
|
|
|
import { SETTINGS_UPDATED } from '../base/settings';
|
2020-01-24 16:28:47 +00:00
|
|
|
import {
|
|
|
|
getCurrentLayout,
|
2021-01-21 20:46:47 +00:00
|
|
|
LAYOUTS
|
2020-01-24 16:28:47 +00:00
|
|
|
} from '../video-layout';
|
|
|
|
|
2022-02-24 12:20:37 +00:00
|
|
|
import { SET_USER_FILMSTRIP_WIDTH } from './actionTypes';
|
2021-08-18 22:34:01 +00:00
|
|
|
import {
|
2022-02-24 12:20:37 +00:00
|
|
|
setFilmstripWidth,
|
2021-08-18 22:34:01 +00:00
|
|
|
setHorizontalViewDimensions,
|
|
|
|
setTileViewDimensions,
|
|
|
|
setVerticalViewDimensions
|
2021-08-23 23:02:41 +00:00
|
|
|
} from './actions';
|
2022-02-24 12:20:37 +00:00
|
|
|
import { DEFAULT_FILMSTRIP_WIDTH, MIN_STAGE_VIEW_WIDTH } from './constants';
|
2021-08-23 23:02:41 +00:00
|
|
|
import { updateRemoteParticipants, updateRemoteParticipantsOnLeave } from './functions';
|
2022-02-24 12:20:37 +00:00
|
|
|
import { isFilmstripResizable } from './functions.web';
|
2021-08-23 23:02:41 +00:00
|
|
|
import './subscriber';
|
2020-06-04 14:09:13 +00:00
|
|
|
|
2020-01-24 16:28:47 +00:00
|
|
|
/**
|
|
|
|
* The middleware of the feature Filmstrip.
|
|
|
|
*/
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
2021-09-10 17:37:05 +00:00
|
|
|
if (action.type === PARTICIPANT_LEFT) {
|
|
|
|
// This has to be executed before we remove the participant from features/base/participants state in order to
|
|
|
|
// remove the related thumbnail component before we need to re-render it. If we do this after next()
|
|
|
|
// we will be in sitation where the participant exists in the remoteParticipants array in features/filmstrip
|
|
|
|
// but doesn't exist in features/base/participants state which will lead to rendering a thumbnail for
|
|
|
|
// non-existing participant.
|
|
|
|
updateRemoteParticipantsOnLeave(store, action.participant?.id);
|
|
|
|
}
|
|
|
|
|
2020-01-24 16:28:47 +00:00
|
|
|
const result = next(action);
|
|
|
|
|
|
|
|
switch (action.type) {
|
|
|
|
case CLIENT_RESIZED: {
|
|
|
|
const state = store.getState();
|
|
|
|
const layout = getCurrentLayout(state);
|
|
|
|
|
|
|
|
switch (layout) {
|
|
|
|
case LAYOUTS.TILE_VIEW: {
|
|
|
|
const { gridDimensions } = state['features/filmstrip'].tileViewDimensions;
|
2021-03-26 20:23:05 +00:00
|
|
|
|
|
|
|
store.dispatch(setTileViewDimensions(gridDimensions));
|
2020-01-24 16:28:47 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LAYOUTS.HORIZONTAL_FILMSTRIP_VIEW:
|
2021-03-26 20:23:05 +00:00
|
|
|
store.dispatch(setHorizontalViewDimensions());
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LAYOUTS.VERTICAL_FILMSTRIP_VIEW:
|
|
|
|
store.dispatch(setVerticalViewDimensions());
|
2020-01-24 16:28:47 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-02-24 12:20:37 +00:00
|
|
|
|
|
|
|
if (isFilmstripResizable(state)) {
|
|
|
|
const { width: filmstripWidth } = state['features/filmstrip'];
|
|
|
|
const { clientWidth } = action;
|
|
|
|
let width;
|
|
|
|
|
|
|
|
if (filmstripWidth.current > clientWidth - MIN_STAGE_VIEW_WIDTH) {
|
|
|
|
width = Math.max(clientWidth - MIN_STAGE_VIEW_WIDTH, DEFAULT_FILMSTRIP_WIDTH);
|
|
|
|
} else {
|
|
|
|
width = Math.min(clientWidth - MIN_STAGE_VIEW_WIDTH, filmstripWidth.userSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (width !== filmstripWidth.current) {
|
|
|
|
store.dispatch(setFilmstripWidth(width));
|
|
|
|
}
|
|
|
|
}
|
2020-01-24 16:28:47 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-08-18 22:34:01 +00:00
|
|
|
case PARTICIPANT_JOINED: {
|
2021-08-19 21:56:45 +00:00
|
|
|
updateRemoteParticipants(store, action.participant?.id);
|
2021-08-18 22:34:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-01-21 20:46:47 +00:00
|
|
|
case SETTINGS_UPDATED: {
|
|
|
|
if (typeof action.settings?.localFlipX === 'boolean') {
|
|
|
|
// TODO: This needs to be removed once the large video is Reactified.
|
|
|
|
VideoLayout.onLocalFlipXChanged();
|
2020-01-24 16:28:47 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-02-24 12:20:37 +00:00
|
|
|
case SET_USER_FILMSTRIP_WIDTH: {
|
|
|
|
VideoLayout.refreshLayout();
|
|
|
|
}
|
2020-01-24 16:28:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
});
|