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 {
|
2023-01-24 18:58:58 +00:00
|
|
|
getMultipleVideoSendingSupportFeatureFlag,
|
|
|
|
getSsrcRewritingFeatureFlag
|
2022-08-29 18:23:21 +00:00
|
|
|
} from '../config/functions.any';
|
2023-01-24 18:58:58 +00:00
|
|
|
import { VIDEO_TYPE } from '../media/constants';
|
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';
|
2023-01-24 18:58:58 +00:00
|
|
|
import { getRemoteScreensharesBasedOnPresence } from './functions';
|
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)
|
|
|
|
);
|
|
|
|
|
2023-01-24 18:58:58 +00:00
|
|
|
StateListenerRegistry.register(
|
|
|
|
/* selector */ state => state['features/base/participants'].remoteVideoSources,
|
|
|
|
/* listener */(remoteVideoSources, store) => getSsrcRewritingFeatureFlag(store.getState())
|
|
|
|
&& _updateScreenshareParticipantsBasedOnPresence(store)
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compares the old and new screenshare lists provided and creates/removes the virtual screenshare participant
|
|
|
|
* tiles accodingly.
|
|
|
|
*
|
|
|
|
* @param {Array<string>} oldScreenshareSourceNames - List of old screenshare source names.
|
|
|
|
* @param {Array<string>} newScreenshareSourceNames - Current list of screenshare source names.
|
|
|
|
* @param {Object} store - The redux store.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function _createOrRemoveVirtualParticipants(
|
|
|
|
oldScreenshareSourceNames: string[],
|
|
|
|
newScreenshareSourceNames: string[],
|
|
|
|
store: IStore): void {
|
|
|
|
const { dispatch, getState } = store;
|
|
|
|
const conference = getCurrentConference(getState());
|
|
|
|
const removedScreenshareSourceNames = _.difference(oldScreenshareSourceNames, newScreenshareSourceNames);
|
|
|
|
const addedScreenshareSourceNames = _.difference(newScreenshareSourceNames, oldScreenshareSourceNames);
|
|
|
|
|
|
|
|
if (removedScreenshareSourceNames.length) {
|
|
|
|
removedScreenshareSourceNames.forEach(id => dispatch(participantLeft(id, conference, {
|
|
|
|
fakeParticipant: FakeParticipant.RemoteScreenShare
|
|
|
|
})));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addedScreenshareSourceNames.length) {
|
|
|
|
addedScreenshareSourceNames.forEach(id => dispatch(
|
|
|
|
createVirtualScreenshareParticipant(id, false, conference)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-29 14:32:16 +00:00
|
|
|
/**
|
|
|
|
* Handles creating and removing virtual screenshare participants.
|
|
|
|
*
|
|
|
|
* @param {*} store - The redux store.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2023-01-24 18:58:58 +00:00
|
|
|
function _updateScreenshareParticipants(store: IStore): void {
|
|
|
|
const { dispatch, getState } = store;
|
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) => {
|
2023-01-24 18:58:58 +00:00
|
|
|
if (track.videoType === VIDEO_TYPE.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, {
|
2023-01-24 18:58:58 +00:00
|
|
|
fakeParticipant: FakeParticipant.LocalScreenShare
|
2022-09-06 06:51:38 +00:00
|
|
|
}));
|
2022-08-29 18:23:21 +00:00
|
|
|
}
|
2022-04-29 14:32:16 +00:00
|
|
|
}
|
|
|
|
|
2023-01-24 18:58:58 +00:00
|
|
|
if (getSsrcRewritingFeatureFlag(state)) {
|
|
|
|
return;
|
2022-04-29 14:32:16 +00:00
|
|
|
}
|
|
|
|
|
2023-01-24 18:58:58 +00:00
|
|
|
_createOrRemoveVirtualParticipants(previousScreenshareSourceNames, currentScreenshareSourceNames, store);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles the creation and removal of remote virtual screenshare participants when ssrc-rewriting is enabled.
|
|
|
|
*
|
|
|
|
* @param {Object} store - The redux store.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
function _updateScreenshareParticipantsBasedOnPresence(store: IStore): void {
|
|
|
|
const { getState } = store;
|
|
|
|
const state = getState();
|
|
|
|
const { sortedRemoteVirtualScreenshareParticipants } = state['features/base/participants'];
|
|
|
|
const previousScreenshareSourceNames = [ ...sortedRemoteVirtualScreenshareParticipants.keys() ];
|
|
|
|
const currentScreenshareSourceNames = getRemoteScreensharesBasedOnPresence(state);
|
|
|
|
|
|
|
|
_createOrRemoveVirtualParticipants(previousScreenshareSourceNames, currentScreenshareSourceNames, store);
|
2022-04-29 14:32:16 +00:00
|
|
|
}
|