選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

subscriber.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. if (!getAutoPinSetting() || isFollowMeActive(store)) {
  16. return;
  17. }
  18. const oldScreenSharesOrder = store.getState()['features/video-layout'].remoteScreenShares || [];
  19. const knownSharingParticipantIds = tracks.reduce((acc, track) => {
  20. if (track.mediaType === 'video' && track.videoType === 'desktop') {
  21. const skipTrack = getAutoPinSetting() === 'remote-only' && track.local;
  22. if (!skipTrack) {
  23. acc.push(track.participantId);
  24. }
  25. }
  26. return acc;
  27. }, []);
  28. // Filter out any participants which are no longer screen sharing
  29. // by looping through the known sharing participants and removing any
  30. // participant IDs which are no longer sharing.
  31. const newScreenSharesOrder = oldScreenSharesOrder.filter(
  32. participantId => knownSharingParticipantIds.includes(participantId));
  33. // Make sure all new sharing participant get added to the end of the
  34. // known screen shares.
  35. knownSharingParticipantIds.forEach(participantId => {
  36. if (!newScreenSharesOrder.includes(participantId)) {
  37. newScreenSharesOrder.push(participantId);
  38. }
  39. });
  40. if (!equals(oldScreenSharesOrder, newScreenSharesOrder)) {
  41. store.dispatch(
  42. setRemoteParticipantsWithScreenShare(newScreenSharesOrder));
  43. updateAutoPinnedParticipant(oldScreenSharesOrder, store);
  44. }
  45. }, 100));