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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 { setParticipantsWithScreenShare } from './actions';
  15. import { shouldDisplayTileView } from './functions';
  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(setMaxReceiverVideoQuality(VIDEO_QUALITY_LEVELS.HIGH));
  29. if (_getAutoPinSetting()) {
  30. _updateAutoPinnedParticipant(store);
  31. }
  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. if (!_getAutoPinSetting() || isFollowMeActive(store)) {
  44. return;
  45. }
  46. const oldScreenSharesOrder = store.getState()['features/video-layout'].screenShares || [];
  47. const knownSharingParticipantIds = tracks.reduce((acc, track) => {
  48. if (track.mediaType === 'video' && track.videoType === 'desktop') {
  49. const skipTrack = _getAutoPinSetting() === 'remote-only' && track.local;
  50. if (!skipTrack) {
  51. acc.push(track.participantId);
  52. }
  53. }
  54. return acc;
  55. }, []);
  56. // Filter out any participants which are no longer screen sharing
  57. // by looping through the known sharing participants and removing any
  58. // participant IDs which are no longer sharing.
  59. const newScreenSharesOrder = oldScreenSharesOrder.filter(
  60. participantId => knownSharingParticipantIds.includes(participantId));
  61. // Make sure all new sharing participant get added to the end of the
  62. // known screen shares.
  63. knownSharingParticipantIds.forEach(participantId => {
  64. if (!newScreenSharesOrder.includes(participantId)) {
  65. newScreenSharesOrder.push(participantId);
  66. }
  67. });
  68. if (!equals(oldScreenSharesOrder, newScreenSharesOrder)) {
  69. store.dispatch(
  70. setParticipantsWithScreenShare(newScreenSharesOrder));
  71. _updateAutoPinnedParticipant(store);
  72. }
  73. }, 100));
  74. /**
  75. * A selector for retrieving the current automatic pinning setting.
  76. *
  77. * @private
  78. * @returns {string|undefined} The string "remote-only" is returned if only
  79. * remote screensharing should be automatically pinned, any other truthy value
  80. * means automatically pin all screenshares. Falsy means do not automatically
  81. * pin any screenshares.
  82. */
  83. function _getAutoPinSetting() {
  84. return typeof interfaceConfig === 'object'
  85. ? interfaceConfig.AUTO_PIN_LATEST_SCREEN_SHARE
  86. : 'remote-only';
  87. }
  88. /**
  89. * Private helper to automatically pin the latest screen share stream or unpin
  90. * if there are no more screen share streams.
  91. *
  92. * @param {Store} store - The redux store.
  93. * @returns {void}
  94. */
  95. function _updateAutoPinnedParticipant({ dispatch, getState }) {
  96. const state = getState();
  97. const screenShares = state['features/video-layout'].screenShares;
  98. if (!screenShares) {
  99. return;
  100. }
  101. const latestScreenshareParticipantId
  102. = screenShares[screenShares.length - 1];
  103. if (latestScreenshareParticipantId) {
  104. dispatch(pinParticipant(latestScreenshareParticipantId));
  105. } else if (getPinnedParticipant(state['features/base/participants'])) {
  106. dispatch(pinParticipant(null));
  107. }
  108. }