2021-08-23 23:02:41 +00:00
|
|
|
// @flow
|
|
|
|
|
2021-12-07 08:24:00 +00:00
|
|
|
import { getParticipantCount } from '../base/participants';
|
|
|
|
|
2021-08-23 23:02:41 +00:00
|
|
|
import { setRemoteParticipants } from './actions';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes the reorderd list of the remote participants.
|
|
|
|
*
|
|
|
|
* @param {*} store - The redux store.
|
2021-08-19 21:56:45 +00:00
|
|
|
* @param {string} participantId - The endpoint id of the participant that joined the call.
|
2021-08-23 23:02:41 +00:00
|
|
|
* @returns {void}
|
|
|
|
* @private
|
|
|
|
*/
|
2021-08-23 22:39:09 +00:00
|
|
|
export function updateRemoteParticipants(store: Object, participantId: ?number) {
|
2021-08-23 23:02:41 +00:00
|
|
|
const state = store.getState();
|
2021-09-10 17:37:05 +00:00
|
|
|
const { testing = {} } = state['features/base/config'];
|
|
|
|
const enableThumbnailReordering = testing.enableThumbnailReordering ?? true;
|
2021-08-19 21:56:45 +00:00
|
|
|
let reorderedParticipants = [];
|
|
|
|
|
|
|
|
if (!enableThumbnailReordering) {
|
|
|
|
if (participantId) {
|
|
|
|
const { remoteParticipants } = state['features/filmstrip'];
|
|
|
|
|
|
|
|
reorderedParticipants = [ ...remoteParticipants, participantId ];
|
|
|
|
store.dispatch(setRemoteParticipants(reorderedParticipants));
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-23 22:39:09 +00:00
|
|
|
const {
|
|
|
|
fakeParticipants,
|
|
|
|
sortedRemoteParticipants,
|
|
|
|
sortedRemoteScreenshares,
|
|
|
|
speakersList
|
|
|
|
} = state['features/base/participants'];
|
2021-08-23 23:02:41 +00:00
|
|
|
const remoteParticipants = new Map(sortedRemoteParticipants);
|
2021-08-23 22:39:09 +00:00
|
|
|
const screenShares = new Map(sortedRemoteScreenshares);
|
2021-08-23 23:02:41 +00:00
|
|
|
const sharedVideos = fakeParticipants ? Array.from(fakeParticipants.keys()) : [];
|
2021-08-23 22:39:09 +00:00
|
|
|
const speakers = new Map(speakersList);
|
2021-08-23 23:02:41 +00:00
|
|
|
|
2021-08-23 22:39:09 +00:00
|
|
|
for (const screenshare of screenShares.keys()) {
|
2021-08-23 23:02:41 +00:00
|
|
|
remoteParticipants.delete(screenshare);
|
2021-08-19 21:56:45 +00:00
|
|
|
speakers.delete(screenshare);
|
2021-08-23 23:02:41 +00:00
|
|
|
}
|
|
|
|
for (const sharedVideo of sharedVideos) {
|
|
|
|
remoteParticipants.delete(sharedVideo);
|
2021-08-19 21:56:45 +00:00
|
|
|
speakers.delete(sharedVideo);
|
2021-08-23 23:02:41 +00:00
|
|
|
}
|
2021-08-19 21:56:45 +00:00
|
|
|
for (const speaker of speakers.keys()) {
|
2021-08-23 23:02:41 +00:00
|
|
|
remoteParticipants.delete(speaker);
|
|
|
|
}
|
2021-08-19 21:56:45 +00:00
|
|
|
|
|
|
|
// Always update the order of the thumnails.
|
|
|
|
reorderedParticipants = [
|
2021-08-23 22:39:09 +00:00
|
|
|
...Array.from(screenShares.keys()),
|
2021-08-19 21:56:45 +00:00
|
|
|
...sharedVideos,
|
|
|
|
...Array.from(speakers.keys()),
|
|
|
|
...Array.from(remoteParticipants.keys())
|
|
|
|
];
|
2021-08-23 23:02:41 +00:00
|
|
|
|
|
|
|
store.dispatch(setRemoteParticipants(reorderedParticipants));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Private helper to calculate the reordered list of remote participants when a participant leaves.
|
|
|
|
*
|
|
|
|
* @param {*} store - The redux store.
|
|
|
|
* @param {string} participantId - The endpoint id of the participant leaving the call.
|
|
|
|
* @returns {void}
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
export function updateRemoteParticipantsOnLeave(store: Object, participantId: ?string = null) {
|
|
|
|
if (!participantId) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const state = store.getState();
|
|
|
|
const { remoteParticipants } = state['features/filmstrip'];
|
|
|
|
const reorderedParticipants = new Set(remoteParticipants);
|
|
|
|
|
|
|
|
reorderedParticipants.delete(participantId)
|
|
|
|
&& store.dispatch(setRemoteParticipants(Array.from(reorderedParticipants)));
|
|
|
|
}
|
2021-12-07 08:24:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the disable self view flag.
|
|
|
|
*
|
|
|
|
* @param {Object} state - Redux state.
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
export function getDisableSelfView(state: Object) {
|
|
|
|
const { disableSelfView } = state['features/base/settings'];
|
|
|
|
const participantsCount = getParticipantCount(state);
|
|
|
|
|
|
|
|
return participantsCount === 1 ? false : disableSelfView;
|
|
|
|
}
|