2022-10-27 07:33:11 +00:00
|
|
|
import StateListenerRegistry from '../base/redux/StateListenerRegistry';
|
|
|
|
import { equals } from '../base/redux/functions';
|
|
|
|
import { isFollowMeActive } from '../follow-me/functions';
|
2020-04-30 21:25:34 +00:00
|
|
|
|
2022-11-10 08:45:56 +00:00
|
|
|
import { virtualScreenshareParticipantsUpdated } from './actions';
|
|
|
|
import { getAutoPinSetting, updateAutoPinnedParticipant } from './functions';
|
2018-08-08 18:48:23 +00:00
|
|
|
|
2022-04-04 18:57:58 +00:00
|
|
|
StateListenerRegistry.register(
|
2022-04-29 14:32:16 +00:00
|
|
|
/* selector */ state => state['features/base/participants'].sortedRemoteVirtualScreenshareParticipants,
|
|
|
|
/* listener */ (sortedRemoteVirtualScreenshareParticipants, store) => {
|
2022-04-04 18:57:58 +00:00
|
|
|
const oldScreenSharesOrder = store.getState()['features/video-layout'].remoteScreenShares || [];
|
2022-04-29 14:32:16 +00:00
|
|
|
const knownSharingParticipantIds = [ ...sortedRemoteVirtualScreenshareParticipants.keys() ];
|
2022-04-04 18:57:58 +00:00
|
|
|
|
|
|
|
// Filter out any participants which are no longer screen sharing
|
|
|
|
// by looping through the known sharing participants and removing any
|
|
|
|
// participant IDs which are no longer sharing.
|
|
|
|
const newScreenSharesOrder = oldScreenSharesOrder.filter(
|
|
|
|
participantId => knownSharingParticipantIds.includes(participantId));
|
|
|
|
|
|
|
|
// Make sure all new sharing participant get added to the end of the
|
|
|
|
// known screen shares.
|
|
|
|
knownSharingParticipantIds.forEach(participantId => {
|
|
|
|
if (!newScreenSharesOrder.includes(participantId)) {
|
|
|
|
newScreenSharesOrder.push(participantId);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!equals(oldScreenSharesOrder, newScreenSharesOrder)) {
|
2022-04-29 14:32:16 +00:00
|
|
|
store.dispatch(virtualScreenshareParticipantsUpdated(newScreenSharesOrder));
|
2022-04-04 18:57:58 +00:00
|
|
|
|
2022-08-24 21:17:17 +00:00
|
|
|
if (getAutoPinSetting() && !isFollowMeActive(store)) {
|
|
|
|
updateAutoPinnedParticipant(oldScreenSharesOrder, store);
|
|
|
|
}
|
2022-04-04 18:57:58 +00:00
|
|
|
}
|
|
|
|
});
|