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

subscriber.js 2.6KB

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