2022-04-29 14:32:16 +00:00
|
|
|
import _ from 'lodash';
|
|
|
|
|
2022-09-21 08:32:50 +00:00
|
|
|
import { IStore } from '../../app/types';
|
|
|
|
import { getCurrentConference } from '../conference/functions';
|
2022-08-29 18:23:21 +00:00
|
|
|
import {
|
2022-11-08 19:15:49 +00:00
|
|
|
getMultipleVideoSendingSupportFeatureFlag
|
2022-08-29 18:23:21 +00:00
|
|
|
} from '../config/functions.any';
|
2022-09-21 08:32:50 +00:00
|
|
|
import StateListenerRegistry from '../redux/StateListenerRegistry';
|
2022-04-29 14:32:16 +00:00
|
|
|
|
|
|
|
import { createVirtualScreenshareParticipant, participantLeft } from './actions';
|
2022-10-06 11:12:57 +00:00
|
|
|
import { FakeParticipant } from './types';
|
2022-04-29 14:32:16 +00:00
|
|
|
|
|
|
|
StateListenerRegistry.register(
|
|
|
|
/* selector */ state => state['features/base/tracks'],
|
|
|
|
/* listener */(tracks, store) => _updateScreenshareParticipants(store)
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles creating and removing virtual screenshare participants.
|
|
|
|
*
|
|
|
|
* @param {*} store - The redux store.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-09-21 08:32:50 +00:00
|
|
|
function _updateScreenshareParticipants({ getState, dispatch }: IStore) {
|
2022-04-29 14:32:16 +00:00
|
|
|
const state = getState();
|
|
|
|
const conference = getCurrentConference(state);
|
|
|
|
const tracks = state['features/base/tracks'];
|
|
|
|
const { sortedRemoteVirtualScreenshareParticipants, localScreenShare } = state['features/base/participants'];
|
|
|
|
const previousScreenshareSourceNames = [ ...sortedRemoteVirtualScreenshareParticipants.keys() ];
|
|
|
|
|
|
|
|
let newLocalSceenshareSourceName;
|
|
|
|
|
2022-09-21 08:32:50 +00:00
|
|
|
const currentScreenshareSourceNames = tracks.reduce((acc: string[], track) => {
|
2022-04-29 14:32:16 +00:00
|
|
|
if (track.videoType === 'desktop' && !track.jitsiTrack.isMuted()) {
|
2022-09-21 08:32:50 +00:00
|
|
|
const sourceName: string = track.jitsiTrack.getSourceName();
|
2022-04-29 14:32:16 +00:00
|
|
|
|
|
|
|
if (track.local) {
|
|
|
|
newLocalSceenshareSourceName = sourceName;
|
|
|
|
} else {
|
|
|
|
acc.push(sourceName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
}, []);
|
|
|
|
|
2022-08-29 18:23:21 +00:00
|
|
|
if (getMultipleVideoSendingSupportFeatureFlag(state)) {
|
|
|
|
if (!localScreenShare && newLocalSceenshareSourceName) {
|
2022-11-30 21:44:19 +00:00
|
|
|
dispatch(createVirtualScreenshareParticipant(newLocalSceenshareSourceName, true, conference));
|
2022-08-29 18:23:21 +00:00
|
|
|
}
|
2022-04-29 14:32:16 +00:00
|
|
|
|
2022-08-29 18:23:21 +00:00
|
|
|
if (localScreenShare && !newLocalSceenshareSourceName) {
|
2022-09-06 06:51:38 +00:00
|
|
|
dispatch(participantLeft(localScreenShare.id, conference, {
|
2022-10-06 11:12:57 +00:00
|
|
|
fakeParticipant: FakeParticipant.LocalScreenShare,
|
|
|
|
isReplaced: undefined
|
2022-09-06 06:51:38 +00:00
|
|
|
}));
|
2022-08-29 18:23:21 +00:00
|
|
|
}
|
2022-04-29 14:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const removedScreenshareSourceNames = _.difference(previousScreenshareSourceNames, currentScreenshareSourceNames);
|
|
|
|
const addedScreenshareSourceNames = _.difference(currentScreenshareSourceNames, previousScreenshareSourceNames);
|
|
|
|
|
|
|
|
if (removedScreenshareSourceNames.length) {
|
2022-09-06 06:51:38 +00:00
|
|
|
removedScreenshareSourceNames.forEach(id => dispatch(participantLeft(id, conference, {
|
2022-10-06 11:12:57 +00:00
|
|
|
fakeParticipant: FakeParticipant.RemoteScreenShare,
|
|
|
|
isReplaced: undefined
|
2022-09-06 06:51:38 +00:00
|
|
|
})));
|
2022-04-29 14:32:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (addedScreenshareSourceNames.length) {
|
2022-11-30 21:44:19 +00:00
|
|
|
addedScreenshareSourceNames.forEach(id => dispatch(
|
|
|
|
createVirtualScreenshareParticipant(id, false, conference)));
|
2022-04-29 14:32:16 +00:00
|
|
|
}
|
|
|
|
}
|