You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

subscriber.ts 2.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import _ from 'lodash';
  2. import { IStore } from '../../app/types';
  3. import { getCurrentConference } from '../conference/functions';
  4. import {
  5. getMultipleVideoSendingSupportFeatureFlag,
  6. getMultipleVideoSupportFeatureFlag
  7. } from '../config/functions.any';
  8. import StateListenerRegistry from '../redux/StateListenerRegistry';
  9. import { createVirtualScreenshareParticipant, participantLeft } from './actions';
  10. import { FakeParticipant } from './types';
  11. StateListenerRegistry.register(
  12. /* selector */ state => state['features/base/tracks'],
  13. /* listener */(tracks, store) => _updateScreenshareParticipants(store)
  14. );
  15. /**
  16. * Handles creating and removing virtual screenshare participants.
  17. *
  18. * @param {*} store - The redux store.
  19. * @returns {void}
  20. */
  21. function _updateScreenshareParticipants({ getState, dispatch }: IStore) {
  22. const state = getState();
  23. if (!getMultipleVideoSupportFeatureFlag(state)) {
  24. return;
  25. }
  26. const conference = getCurrentConference(state);
  27. const tracks = state['features/base/tracks'];
  28. const { sortedRemoteVirtualScreenshareParticipants, localScreenShare } = state['features/base/participants'];
  29. const previousScreenshareSourceNames = [ ...sortedRemoteVirtualScreenshareParticipants.keys() ];
  30. let newLocalSceenshareSourceName;
  31. const currentScreenshareSourceNames = tracks.reduce((acc: string[], track) => {
  32. if (track.videoType === 'desktop' && !track.jitsiTrack.isMuted()) {
  33. const sourceName: string = track.jitsiTrack.getSourceName();
  34. if (track.local) {
  35. newLocalSceenshareSourceName = sourceName;
  36. } else {
  37. acc.push(sourceName);
  38. }
  39. }
  40. return acc;
  41. }, []);
  42. if (getMultipleVideoSendingSupportFeatureFlag(state)) {
  43. if (!localScreenShare && newLocalSceenshareSourceName) {
  44. dispatch(createVirtualScreenshareParticipant(newLocalSceenshareSourceName, true));
  45. }
  46. if (localScreenShare && !newLocalSceenshareSourceName) {
  47. dispatch(participantLeft(localScreenShare.id, conference, {
  48. fakeParticipant: FakeParticipant.LocalScreenShare,
  49. isReplaced: undefined
  50. }));
  51. }
  52. }
  53. const removedScreenshareSourceNames = _.difference(previousScreenshareSourceNames, currentScreenshareSourceNames);
  54. const addedScreenshareSourceNames = _.difference(currentScreenshareSourceNames, previousScreenshareSourceNames);
  55. if (removedScreenshareSourceNames.length) {
  56. removedScreenshareSourceNames.forEach(id => dispatch(participantLeft(id, conference, {
  57. fakeParticipant: FakeParticipant.RemoteScreenShare,
  58. isReplaced: undefined
  59. })));
  60. }
  61. if (addedScreenshareSourceNames.length) {
  62. addedScreenshareSourceNames.forEach(id => dispatch(createVirtualScreenshareParticipant(id, false)));
  63. }
  64. }