2022-11-10 08:45:56 +00:00
|
|
|
import { IStore } from '../app/types';
|
|
|
|
import {
|
|
|
|
getActiveSpeakersToBeDisplayed,
|
|
|
|
getVirtualScreenshareParticipantOwnerId
|
|
|
|
} from '../base/participants/functions';
|
2022-04-04 18:57:58 +00:00
|
|
|
|
2021-08-23 23:02:41 +00:00
|
|
|
import { setRemoteParticipants } from './actions';
|
2022-05-06 10:18:57 +00:00
|
|
|
import { isFilmstripScrollVisible } from './functions';
|
2021-08-23 23:02:41 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2022-11-10 08:45:56 +00:00
|
|
|
export function updateRemoteParticipants(store: IStore, participantId?: string) {
|
2021-08-23 23:02:41 +00:00
|
|
|
const state = store.getState();
|
2021-08-19 21:56:45 +00:00
|
|
|
let reorderedParticipants = [];
|
2022-04-29 14:32:16 +00:00
|
|
|
const { sortedRemoteVirtualScreenshareParticipants } = state['features/base/participants'];
|
2022-04-04 18:57:58 +00:00
|
|
|
|
2022-10-20 23:01:08 +00:00
|
|
|
if (!isFilmstripScrollVisible(state) && !sortedRemoteVirtualScreenshareParticipants.size) {
|
2021-08-19 21:56:45 +00:00
|
|
|
if (participantId) {
|
|
|
|
const { remoteParticipants } = state['features/filmstrip'];
|
|
|
|
|
|
|
|
reorderedParticipants = [ ...remoteParticipants, participantId ];
|
2022-10-18 10:09:04 +00:00
|
|
|
store.dispatch(setRemoteParticipants(Array.from(new Set(reorderedParticipants))));
|
2021-08-19 21:56:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-08-23 22:39:09 +00:00
|
|
|
const {
|
|
|
|
fakeParticipants,
|
2022-11-08 19:15:49 +00:00
|
|
|
sortedRemoteParticipants
|
2021-08-23 22:39:09 +00:00
|
|
|
} = state['features/base/participants'];
|
2021-08-23 23:02:41 +00:00
|
|
|
const remoteParticipants = new Map(sortedRemoteParticipants);
|
2022-04-29 14:32:16 +00:00
|
|
|
const screenShareParticipants = sortedRemoteVirtualScreenshareParticipants
|
|
|
|
? [ ...sortedRemoteVirtualScreenshareParticipants.keys() ] : [];
|
2021-08-23 23:02:41 +00:00
|
|
|
const sharedVideos = fakeParticipants ? Array.from(fakeParticipants.keys()) : [];
|
2022-07-20 19:51:47 +00:00
|
|
|
const speakers = getActiveSpeakersToBeDisplayed(state);
|
2021-08-23 23:02:41 +00:00
|
|
|
|
2022-11-08 19:15:49 +00:00
|
|
|
for (const screenshare of screenShareParticipants) {
|
|
|
|
const ownerId = getVirtualScreenshareParticipantOwnerId(screenshare);
|
2022-04-04 18:57:58 +00:00
|
|
|
|
2022-11-08 19:15:49 +00:00
|
|
|
remoteParticipants.delete(ownerId);
|
|
|
|
remoteParticipants.delete(screenshare);
|
|
|
|
speakers.delete(ownerId);
|
2021-08-23 23:02:41 +00:00
|
|
|
}
|
2022-04-04 18:57:58 +00:00
|
|
|
|
2021-08-23 23:02:41 +00:00
|
|
|
for (const sharedVideo of sharedVideos) {
|
|
|
|
remoteParticipants.delete(sharedVideo);
|
|
|
|
}
|
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
|
|
|
|
2022-11-08 19:15:49 +00:00
|
|
|
// Always update the order of the thumnails.
|
2022-11-10 08:45:56 +00:00
|
|
|
const participantsWithScreenShare = screenShareParticipants.reduce<string[]>((acc, screenshare) => {
|
2022-11-08 19:15:49 +00:00
|
|
|
const ownerId = getVirtualScreenshareParticipantOwnerId(screenshare);
|
|
|
|
|
|
|
|
acc.push(ownerId);
|
|
|
|
acc.push(screenshare);
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
reorderedParticipants = [
|
|
|
|
...participantsWithScreenShare,
|
|
|
|
...sharedVideos,
|
|
|
|
...Array.from(speakers.keys()),
|
|
|
|
...Array.from(remoteParticipants.keys())
|
|
|
|
];
|
2021-08-23 23:02:41 +00:00
|
|
|
|
2022-10-18 10:09:04 +00:00
|
|
|
store.dispatch(setRemoteParticipants(Array.from(new Set(reorderedParticipants))));
|
2021-08-23 23:02:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2022-11-10 08:45:56 +00:00
|
|
|
export function updateRemoteParticipantsOnLeave(store: IStore, participantId: string | null = null) {
|
2021-08-23 23:02:41 +00:00
|
|
|
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)));
|
|
|
|
}
|