2022-10-27 07:33:11 +00:00
|
|
|
import { IStore } from '../app/types';
|
|
|
|
import { getCurrentConference } from '../base/conference/functions';
|
|
|
|
import { PARTICIPANT_LEFT, PIN_PARTICIPANT } from '../base/participants/actionTypes';
|
|
|
|
import { pinParticipant } from '../base/participants/actions';
|
|
|
|
import { getParticipantById, getPinnedParticipant } from '../base/participants/functions';
|
|
|
|
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
|
|
|
|
import StateListenerRegistry from '../base/redux/StateListenerRegistry';
|
|
|
|
import { SET_DOCUMENT_EDITING_STATUS } from '../etherpad/actionTypes';
|
2022-03-29 12:35:49 +00:00
|
|
|
import { isStageFilmstripEnabled } from '../filmstrip/functions';
|
2022-10-27 07:33:11 +00:00
|
|
|
import { isFollowMeActive } from '../follow-me/functions';
|
2018-11-28 19:36:23 +00:00
|
|
|
|
|
|
|
import { SET_TILE_VIEW } from './actionTypes';
|
2022-12-28 19:32:24 +00:00
|
|
|
import { setTileView } from './actions';
|
2021-06-04 21:11:18 +00:00
|
|
|
import { getAutoPinSetting, updateAutoPinnedParticipant } from './functions';
|
2018-11-28 19:36:23 +00:00
|
|
|
|
2020-06-04 14:09:13 +00:00
|
|
|
import './subscriber';
|
|
|
|
|
2022-10-27 07:33:11 +00:00
|
|
|
let previousTileViewEnabled: boolean | undefined;
|
2020-07-23 13:12:25 +00:00
|
|
|
|
2018-11-28 19:36:23 +00:00
|
|
|
/**
|
|
|
|
* Middleware which intercepts actions and updates tile view related state.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
2021-06-04 21:11:18 +00:00
|
|
|
|
|
|
|
// we want to extract the leaving participant and check its type before actually the participant being removed.
|
|
|
|
let shouldUpdateAutoPin = false;
|
|
|
|
|
|
|
|
switch (action.type) {
|
|
|
|
case PARTICIPANT_LEFT: {
|
|
|
|
if (!getAutoPinSetting() || isFollowMeActive(store)) {
|
|
|
|
break;
|
|
|
|
}
|
2022-10-06 11:12:57 +00:00
|
|
|
shouldUpdateAutoPin = Boolean(getParticipantById(store.getState(), action.participant.id)?.fakeParticipant);
|
2021-06-04 21:11:18 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-23 13:12:25 +00:00
|
|
|
const result = next(action);
|
|
|
|
|
2018-11-28 19:36:23 +00:00
|
|
|
switch (action.type) {
|
2020-07-23 13:12:25 +00:00
|
|
|
|
|
|
|
// Actions that temporarily clear the user preferred state of tile view,
|
|
|
|
// then re-set it when needed.
|
2018-11-28 19:36:23 +00:00
|
|
|
case PIN_PARTICIPANT: {
|
2023-02-23 12:41:29 +00:00
|
|
|
const pinnedParticipant = action.participant?.id;
|
2018-11-28 19:36:23 +00:00
|
|
|
|
2020-07-23 13:12:25 +00:00
|
|
|
if (pinnedParticipant) {
|
|
|
|
_storeTileViewStateAndClear(store);
|
|
|
|
} else {
|
|
|
|
_restoreTileViewState(store);
|
2018-11-28 19:36:23 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2018-11-28 19:48:15 +00:00
|
|
|
case SET_DOCUMENT_EDITING_STATUS:
|
|
|
|
if (action.editing) {
|
2020-07-23 13:12:25 +00:00
|
|
|
_storeTileViewStateAndClear(store);
|
|
|
|
} else {
|
|
|
|
_restoreTileViewState(store);
|
2018-11-28 19:48:15 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-07-23 13:12:25 +00:00
|
|
|
// Things to update when tile view state changes
|
2022-03-29 08:45:09 +00:00
|
|
|
case SET_TILE_VIEW: {
|
|
|
|
const state = store.getState();
|
|
|
|
const stageFilmstrip = isStageFilmstripEnabled(state);
|
|
|
|
|
|
|
|
if (action.enabled && !stageFilmstrip && getPinnedParticipant(state)) {
|
2020-07-23 13:12:25 +00:00
|
|
|
store.dispatch(pinParticipant(null));
|
|
|
|
}
|
2022-03-04 23:17:46 +00:00
|
|
|
break;
|
2022-03-29 08:45:09 +00:00
|
|
|
}
|
2020-07-23 13:12:25 +00:00
|
|
|
}
|
|
|
|
|
2021-06-04 21:11:18 +00:00
|
|
|
if (shouldUpdateAutoPin) {
|
|
|
|
const screenShares = store.getState()['features/video-layout'].remoteScreenShares || [];
|
|
|
|
|
|
|
|
updateAutoPinnedParticipant(screenShares, store);
|
|
|
|
}
|
2018-11-28 19:48:15 +00:00
|
|
|
|
2020-07-23 13:12:25 +00:00
|
|
|
return result;
|
|
|
|
});
|
2018-11-28 19:48:15 +00:00
|
|
|
|
2020-07-23 13:12:25 +00:00
|
|
|
/**
|
|
|
|
* Set up state change listener to perform maintenance tasks when the conference
|
|
|
|
* is left or failed.
|
|
|
|
*/
|
|
|
|
StateListenerRegistry.register(
|
|
|
|
state => getCurrentConference(state),
|
|
|
|
(conference, { dispatch }, previousConference) => {
|
|
|
|
if (conference !== previousConference) {
|
|
|
|
// conference changed, left or failed...
|
|
|
|
// Clear tile view state.
|
|
|
|
dispatch(setTileView());
|
2018-11-28 19:36:23 +00:00
|
|
|
}
|
2020-07-23 13:12:25 +00:00
|
|
|
});
|
2018-11-28 19:36:23 +00:00
|
|
|
|
2020-07-23 13:12:25 +00:00
|
|
|
/**
|
2021-06-04 21:11:18 +00:00
|
|
|
* Restores tile view state, if it wasn't updated since then.
|
2020-07-23 13:12:25 +00:00
|
|
|
*
|
|
|
|
* @param {Object} store - The Redux Store.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-10-27 07:33:11 +00:00
|
|
|
function _restoreTileViewState({ dispatch, getState }: IStore) {
|
2020-07-23 13:12:25 +00:00
|
|
|
const { tileViewEnabled } = getState()['features/video-layout'];
|
|
|
|
|
|
|
|
if (tileViewEnabled === undefined && previousTileViewEnabled !== undefined) {
|
|
|
|
dispatch(setTileView(previousTileViewEnabled));
|
2018-11-28 19:48:15 +00:00
|
|
|
}
|
2018-11-28 19:36:23 +00:00
|
|
|
|
2020-07-23 13:12:25 +00:00
|
|
|
previousTileViewEnabled = undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores the current tile view state and clears it.
|
|
|
|
*
|
|
|
|
* @param {Object} store - The Redux Store.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-10-27 07:33:11 +00:00
|
|
|
function _storeTileViewStateAndClear({ dispatch, getState }: IStore) {
|
2020-07-23 13:12:25 +00:00
|
|
|
const { tileViewEnabled } = getState()['features/video-layout'];
|
|
|
|
|
|
|
|
if (tileViewEnabled !== undefined) {
|
|
|
|
previousTileViewEnabled = tileViewEnabled;
|
|
|
|
dispatch(setTileView(undefined));
|
|
|
|
}
|
|
|
|
}
|