2021-08-23 23:02:41 +00:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import { setRemoteParticipants } from './actions';
|
2022-03-15 17:34:46 +00:00
|
|
|
import { isReorderingEnabled } 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
|
|
|
|
*/
|
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-08-19 21:56:45 +00:00
|
|
|
let reorderedParticipants = [];
|
|
|
|
|
2022-03-15 17:34:46 +00:00
|
|
|
if (!isReorderingEnabled(state)) {
|
2021-08-19 21:56:45 +00:00
|
|
|
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)));
|
|
|
|
}
|