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

subscriber.js 4.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 (!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. if (getAutoPinSetting() && !isFollowMeActive(store)) {
  31. updateAutoPinnedParticipant(oldScreenSharesOrder, store);
  32. }
  33. }
  34. });
  35. /**
  36. * For auto-pin mode, listen for changes to the known media tracks and look
  37. * for updates to screen shares. The listener is debounced to avoid state
  38. * thrashing that might occur, especially when switching in or out of p2p.
  39. */
  40. StateListenerRegistry.register(
  41. /* selector */ state => state['features/base/tracks'],
  42. /* listener */ debounce((tracks, store) => {
  43. // Because of the debounce we need to handle removal of screen shares in the middleware. Otherwise it is
  44. // possible to have screen sharing participant that has already left in the remoteScreenShares array.
  45. // This can lead to rendering a thumbnails for already left participants since the remoteScreenShares
  46. // array is used for building the ordered list of remote participants.
  47. if (getMultipleVideoSupportFeatureFlag(store.getState())) {
  48. return;
  49. }
  50. const oldScreenSharesOrder = store.getState()['features/video-layout'].remoteScreenShares || [];
  51. const knownSharingParticipantIds = tracks.reduce((acc, track) => {
  52. if (track.mediaType === 'video' && track.videoType === 'desktop') {
  53. const skipTrack = getAutoPinSetting() === 'remote-only' && track.local;
  54. if (!skipTrack) {
  55. acc.push(track.participantId);
  56. }
  57. }
  58. return acc;
  59. }, []);
  60. // Filter out any participants which are no longer screen sharing
  61. // by looping through the known sharing participants and removing any
  62. // participant IDs which are no longer sharing.
  63. const newScreenSharesOrder = oldScreenSharesOrder.filter(
  64. participantId => knownSharingParticipantIds.includes(participantId));
  65. // Make sure all new sharing participant get added to the end of the
  66. // known screen shares.
  67. knownSharingParticipantIds.forEach(participantId => {
  68. if (!newScreenSharesOrder.includes(participantId)) {
  69. newScreenSharesOrder.push(participantId);
  70. }
  71. });
  72. if (!equals(oldScreenSharesOrder, newScreenSharesOrder)) {
  73. store.dispatch(
  74. setRemoteParticipantsWithScreenShare(newScreenSharesOrder));
  75. if (getAutoPinSetting() && !isFollowMeActive(store)) {
  76. updateAutoPinnedParticipant(oldScreenSharesOrder, store);
  77. }
  78. }
  79. }, 100));