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 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // @flow
  2. import debounce from 'lodash/debounce';
  3. import {
  4. VIDEO_QUALITY_LEVELS,
  5. setMaxReceiverVideoQuality
  6. } from '../base/conference';
  7. import {
  8. getPinnedParticipant,
  9. pinParticipant
  10. } from '../base/participants';
  11. import { StateListenerRegistry, equals } from '../base/redux';
  12. import { isFollowMeActive } from '../follow-me';
  13. import { selectParticipant } from '../large-video';
  14. import { shouldDisplayTileView } from './functions';
  15. import { setParticipantsWithScreenShare } from './actions';
  16. declare var APP: Object;
  17. declare var interfaceConfig: Object;
  18. /**
  19. * StateListenerRegistry provides a reliable way of detecting changes to
  20. * preferred layout state and dispatching additional actions.
  21. */
  22. StateListenerRegistry.register(
  23. /* selector */ state => shouldDisplayTileView(state),
  24. /* listener */ (displayTileView, store) => {
  25. const { dispatch } = store;
  26. dispatch(selectParticipant());
  27. if (!displayTileView) {
  28. dispatch(
  29. setMaxReceiverVideoQuality(VIDEO_QUALITY_LEVELS.HIGH));
  30. if (_getAutoPinSetting()) {
  31. _updateAutoPinnedParticipant(store);
  32. }
  33. }
  34. }
  35. );
  36. /**
  37. * For auto-pin mode, listen for changes to the known media tracks and look
  38. * for updates to screen shares. The listener is debounced to avoid state
  39. * thrashing that might occur, especially when switching in or out of p2p.
  40. */
  41. StateListenerRegistry.register(
  42. /* selector */ state => state['features/base/tracks'],
  43. /* listener */ debounce((tracks, store) => {
  44. if (!_getAutoPinSetting() || isFollowMeActive(store)) {
  45. return;
  46. }
  47. const oldScreenSharesOrder = store.getState()['features/video-layout'].screenShares || [];
  48. const knownSharingParticipantIds = tracks.reduce((acc, track) => {
  49. if (track.mediaType === 'video' && track.videoType === 'desktop') {
  50. const skipTrack = _getAutoPinSetting() === 'remote-only' && track.local;
  51. if (!skipTrack) {
  52. acc.push(track.participantId);
  53. }
  54. }
  55. return acc;
  56. }, []);
  57. // Filter out any participants which are no longer screen sharing
  58. // by looping through the known sharing participants and removing any
  59. // participant IDs which are no longer sharing.
  60. const newScreenSharesOrder = oldScreenSharesOrder.filter(
  61. participantId => knownSharingParticipantIds.includes(participantId));
  62. // Make sure all new sharing participant get added to the end of the
  63. // known screen shares.
  64. knownSharingParticipantIds.forEach(participantId => {
  65. if (!newScreenSharesOrder.includes(participantId)) {
  66. newScreenSharesOrder.push(participantId);
  67. }
  68. });
  69. if (!equals(oldScreenSharesOrder, newScreenSharesOrder)) {
  70. store.dispatch(
  71. setParticipantsWithScreenShare(newScreenSharesOrder));
  72. _updateAutoPinnedParticipant(store);
  73. }
  74. }, 100));
  75. /**
  76. * A selector for retrieving the current automatic pinning setting.
  77. *
  78. * @private
  79. * @returns {string|undefined} The string "remote-only" is returned if only
  80. * remote screensharing should be automatically pinned, any other truthy value
  81. * means automatically pin all screenshares. Falsy means do not automatically
  82. * pin any screenshares.
  83. */
  84. function _getAutoPinSetting() {
  85. return typeof interfaceConfig === 'object'
  86. ? interfaceConfig.AUTO_PIN_LATEST_SCREEN_SHARE
  87. : 'remote-only';
  88. }
  89. /**
  90. * Private helper to automatically pin the latest screen share stream or unpin
  91. * if there are no more screen share streams.
  92. *
  93. * @param {Store} store - The redux store.
  94. * @returns {void}
  95. */
  96. function _updateAutoPinnedParticipant({ dispatch, getState }) {
  97. const state = getState();
  98. const screenShares = state['features/video-layout'].screenShares;
  99. if (!screenShares) {
  100. return;
  101. }
  102. const latestScreenshareParticipantId
  103. = screenShares[screenShares.length - 1];
  104. if (latestScreenshareParticipantId) {
  105. dispatch(pinParticipant(latestScreenshareParticipantId));
  106. } else if (getPinnedParticipant(state['features/base/participants'])) {
  107. dispatch(pinParticipant(null));
  108. }
  109. }