Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

subscriber.js 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // @flow
  2. import debounce from 'lodash/debounce';
  3. import { getMultipleVideoSupportFeatureFlag } from '../base/config';
  4. import { StateListenerRegistry, equals } from '../base/redux';
  5. import { isFollowMeActive } from '../follow-me';
  6. import { setRemoteParticipantsWithScreenShare, virtualScreenshareParticipantsUpdated } from './actions';
  7. import { getAutoPinSetting, updateAutoPinnedParticipant } from './functions';
  8. StateListenerRegistry.register(
  9. /* selector */ state => state['features/base/participants'].sortedRemoteVirtualScreenshareParticipants,
  10. /* listener */ (sortedRemoteVirtualScreenshareParticipants, store) => {
  11. if (!getAutoPinSetting() || isFollowMeActive(store) || !getMultipleVideoSupportFeatureFlag(store.getState())) {
  12. return;
  13. }
  14. const oldScreenSharesOrder = store.getState()['features/video-layout'].remoteScreenShares || [];
  15. const knownSharingParticipantIds = [ ...sortedRemoteVirtualScreenshareParticipants.keys() ];
  16. // Filter out any participants which are no longer screen sharing
  17. // by looping through the known sharing participants and removing any
  18. // participant IDs which are no longer sharing.
  19. const newScreenSharesOrder = oldScreenSharesOrder.filter(
  20. participantId => knownSharingParticipantIds.includes(participantId));
  21. // Make sure all new sharing participant get added to the end of the
  22. // known screen shares.
  23. knownSharingParticipantIds.forEach(participantId => {
  24. if (!newScreenSharesOrder.includes(participantId)) {
  25. newScreenSharesOrder.push(participantId);
  26. }
  27. });
  28. if (!equals(oldScreenSharesOrder, newScreenSharesOrder)) {
  29. store.dispatch(virtualScreenshareParticipantsUpdated(newScreenSharesOrder));
  30. updateAutoPinnedParticipant(oldScreenSharesOrder, store);
  31. }
  32. });
  33. /**
  34. * For auto-pin mode, listen for changes to the known media tracks and look
  35. * for updates to screen shares. The listener is debounced to avoid state
  36. * thrashing that might occur, especially when switching in or out of p2p.
  37. */
  38. StateListenerRegistry.register(
  39. /* selector */ state => state['features/base/tracks'],
  40. /* listener */ debounce((tracks, store) => {
  41. // Because of the debounce we need to handle removal of screen shares in the middleware. Otherwise it is
  42. // possible to have screen sharing participant that has already left in the remoteScreenShares array.
  43. // This can lead to rendering a thumbnails for already left participants since the remoteScreenShares
  44. // array is used for building the ordered list of remote participants.
  45. if (!getAutoPinSetting() || isFollowMeActive(store) || getMultipleVideoSupportFeatureFlag(store.getState())) {
  46. return;
  47. }
  48. const oldScreenSharesOrder = store.getState()['features/video-layout'].remoteScreenShares || [];
  49. const knownSharingParticipantIds = tracks.reduce((acc, track) => {
  50. if (track.mediaType === 'video' && track.videoType === 'desktop') {
  51. const skipTrack = getAutoPinSetting() === 'remote-only' && track.local;
  52. if (!skipTrack) {
  53. acc.push(track.participantId);
  54. }
  55. }
  56. return acc;
  57. }, []);
  58. // Filter out any participants which are no longer screen sharing
  59. // by looping through the known sharing participants and removing any
  60. // participant IDs which are no longer sharing.
  61. const newScreenSharesOrder = oldScreenSharesOrder.filter(
  62. participantId => knownSharingParticipantIds.includes(participantId));
  63. // Make sure all new sharing participant get added to the end of the
  64. // known screen shares.
  65. knownSharingParticipantIds.forEach(participantId => {
  66. if (!newScreenSharesOrder.includes(participantId)) {
  67. newScreenSharesOrder.push(participantId);
  68. }
  69. });
  70. if (!equals(oldScreenSharesOrder, newScreenSharesOrder)) {
  71. store.dispatch(
  72. setRemoteParticipantsWithScreenShare(newScreenSharesOrder));
  73. updateAutoPinnedParticipant(oldScreenSharesOrder, store);
  74. }
  75. }, 100));