2018-08-08 18:48:23 +00:00
|
|
|
// @flow
|
|
|
|
|
2019-08-12 19:25:06 +00:00
|
|
|
import debounce from 'lodash/debounce';
|
|
|
|
|
2022-04-29 14:32:16 +00:00
|
|
|
import { getMultipleVideoSupportFeatureFlag } from '../base/config';
|
2019-04-11 15:53:34 +00:00
|
|
|
import { StateListenerRegistry, equals } from '../base/redux';
|
2020-04-30 21:25:34 +00:00
|
|
|
import { isFollowMeActive } from '../follow-me';
|
|
|
|
|
2022-04-29 14:32:16 +00:00
|
|
|
import { setRemoteParticipantsWithScreenShare, virtualScreenshareParticipantsUpdated } from './actions';
|
2021-06-04 21:11:18 +00:00
|
|
|
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) => {
|
|
|
|
if (!getAutoPinSetting() || isFollowMeActive(store) || !getMultipleVideoSupportFeatureFlag(store.getState())) {
|
2022-04-04 18:57:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
updateAutoPinnedParticipant(oldScreenSharesOrder, store);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2019-04-11 15:53:34 +00:00
|
|
|
/**
|
|
|
|
* For auto-pin mode, listen for changes to the known media tracks and look
|
2019-08-12 19:25:06 +00:00
|
|
|
* for updates to screen shares. The listener is debounced to avoid state
|
|
|
|
* thrashing that might occur, especially when switching in or out of p2p.
|
2019-04-11 15:53:34 +00:00
|
|
|
*/
|
|
|
|
StateListenerRegistry.register(
|
|
|
|
/* selector */ state => state['features/base/tracks'],
|
2019-08-12 19:25:06 +00:00
|
|
|
/* listener */ debounce((tracks, store) => {
|
2022-03-04 23:17:46 +00:00
|
|
|
// Because of the debounce we need to handle removal of screen shares in the middleware. Otherwise it is
|
|
|
|
// possible to have screen sharing participant that has already left in the remoteScreenShares array.
|
|
|
|
// This can lead to rendering a thumbnails for already left participants since the remoteScreenShares
|
|
|
|
// array is used for building the ordered list of remote participants.
|
2022-04-29 14:32:16 +00:00
|
|
|
if (!getAutoPinSetting() || isFollowMeActive(store) || getMultipleVideoSupportFeatureFlag(store.getState())) {
|
2019-04-11 15:53:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-01-28 12:36:01 +00:00
|
|
|
const oldScreenSharesOrder = store.getState()['features/video-layout'].remoteScreenShares || [];
|
2019-04-11 15:53:34 +00:00
|
|
|
const knownSharingParticipantIds = tracks.reduce((acc, track) => {
|
|
|
|
if (track.mediaType === 'video' && track.videoType === 'desktop') {
|
2021-06-04 21:11:18 +00:00
|
|
|
const skipTrack = getAutoPinSetting() === 'remote-only' && track.local;
|
2019-06-21 21:26:03 +00:00
|
|
|
|
|
|
|
if (!skipTrack) {
|
|
|
|
acc.push(track.participantId);
|
|
|
|
}
|
2019-04-11 15:53:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
// 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)) {
|
|
|
|
store.dispatch(
|
2021-01-28 12:36:01 +00:00
|
|
|
setRemoteParticipantsWithScreenShare(newScreenSharesOrder));
|
2019-04-11 15:53:34 +00:00
|
|
|
|
2021-06-04 21:11:18 +00:00
|
|
|
updateAutoPinnedParticipant(oldScreenSharesOrder, store);
|
2018-08-08 18:48:23 +00:00
|
|
|
}
|
2019-08-12 19:25:06 +00:00
|
|
|
}, 100));
|