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.js 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // @flow
  2. import debounce from 'lodash/debounce';
  3. import { StateListenerRegistry, equals } from '../base/redux';
  4. import { isFollowMeActive } from '../follow-me';
  5. import { selectParticipant } from '../large-video/actions.any';
  6. import { setRemoteParticipantsWithScreenShare } from './actions';
  7. import { getAutoPinSetting, updateAutoPinnedParticipant } from './functions';
  8. /**
  9. * StateListenerRegistry provides a reliable way of detecting changes to
  10. * preferred layout state and dispatching additional actions.
  11. */
  12. StateListenerRegistry.register(
  13. /* selector */ state => state['features/video-layout'].tileViewEnabled,
  14. /* listener */ (tileViewEnabled, store) => {
  15. const { dispatch } = store;
  16. dispatch(selectParticipant());
  17. }
  18. );
  19. /**
  20. * For auto-pin mode, listen for changes to the known media tracks and look
  21. * for updates to screen shares. The listener is debounced to avoid state
  22. * thrashing that might occur, especially when switching in or out of p2p.
  23. */
  24. StateListenerRegistry.register(
  25. /* selector */ state => state['features/base/tracks'],
  26. /* listener */ debounce((tracks, store) => {
  27. if (!getAutoPinSetting() || isFollowMeActive(store)) {
  28. return;
  29. }
  30. const oldScreenSharesOrder = store.getState()['features/video-layout'].remoteScreenShares || [];
  31. const knownSharingParticipantIds = tracks.reduce((acc, track) => {
  32. if (track.mediaType === 'video' && track.videoType === 'desktop') {
  33. const skipTrack = getAutoPinSetting() === 'remote-only' && track.local;
  34. if (!skipTrack) {
  35. acc.push(track.participantId);
  36. }
  37. }
  38. return acc;
  39. }, []);
  40. // Filter out any participants which are no longer screen sharing
  41. // by looping through the known sharing participants and removing any
  42. // participant IDs which are no longer sharing.
  43. const newScreenSharesOrder = oldScreenSharesOrder.filter(
  44. participantId => knownSharingParticipantIds.includes(participantId));
  45. // Make sure all new sharing participant get added to the end of the
  46. // known screen shares.
  47. knownSharingParticipantIds.forEach(participantId => {
  48. if (!newScreenSharesOrder.includes(participantId)) {
  49. newScreenSharesOrder.push(participantId);
  50. }
  51. });
  52. if (!equals(oldScreenSharesOrder, newScreenSharesOrder)) {
  53. store.dispatch(
  54. setRemoteParticipantsWithScreenShare(newScreenSharesOrder));
  55. updateAutoPinnedParticipant(oldScreenSharesOrder, store);
  56. }
  57. }, 100));