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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // @flow
  2. import {
  3. VIDEO_QUALITY_LEVELS,
  4. setMaxReceiverVideoQuality
  5. } from '../base/conference';
  6. import {
  7. getPinnedParticipant,
  8. pinParticipant
  9. } from '../base/participants';
  10. import { StateListenerRegistry, equals } from '../base/redux';
  11. import { selectParticipant } from '../large-video';
  12. import { shouldDisplayTileView } from './functions';
  13. import { setParticipantsWithScreenShare } from './actions';
  14. declare var APP: Object;
  15. declare var interfaceConfig: Object;
  16. /**
  17. * StateListenerRegistry provides a reliable way of detecting changes to
  18. * preferred layout state and dispatching additional actions.
  19. */
  20. StateListenerRegistry.register(
  21. /* selector */ state => shouldDisplayTileView(state),
  22. /* listener */ (displayTileView, store) => {
  23. const { dispatch } = store;
  24. dispatch(selectParticipant());
  25. if (!displayTileView) {
  26. dispatch(
  27. setMaxReceiverVideoQuality(VIDEO_QUALITY_LEVELS.HIGH));
  28. if (typeof interfaceConfig === 'object'
  29. && interfaceConfig.AUTO_PIN_LATEST_SCREEN_SHARE) {
  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.
  38. */
  39. StateListenerRegistry.register(
  40. /* selector */ state => state['features/base/tracks'],
  41. /* listener */ (tracks, store) => {
  42. if (typeof interfaceConfig !== 'object'
  43. || !interfaceConfig.AUTO_PIN_LATEST_SCREEN_SHARE) {
  44. return;
  45. }
  46. const oldScreenSharesOrder
  47. = store.getState()['features/video-layout'].screenShares || [];
  48. const knownSharingParticipantIds = tracks.reduce((acc, track) => {
  49. if (track.mediaType === 'video' && track.videoType === 'desktop') {
  50. acc.push(track.participantId);
  51. }
  52. return acc;
  53. }, []);
  54. // Filter out any participants which are no longer screen sharing
  55. // by looping through the known sharing participants and removing any
  56. // participant IDs which are no longer sharing.
  57. const newScreenSharesOrder = oldScreenSharesOrder.filter(
  58. participantId => knownSharingParticipantIds.includes(participantId));
  59. // Make sure all new sharing participant get added to the end of the
  60. // known screen shares.
  61. knownSharingParticipantIds.forEach(participantId => {
  62. if (!newScreenSharesOrder.includes(participantId)) {
  63. newScreenSharesOrder.push(participantId);
  64. }
  65. });
  66. if (!equals(oldScreenSharesOrder, newScreenSharesOrder)) {
  67. store.dispatch(
  68. setParticipantsWithScreenShare(newScreenSharesOrder));
  69. _updateAutoPinnedParticipant(store);
  70. }
  71. }
  72. );
  73. /**
  74. * Private helper to automatically pin the latest screen share stream or unpin
  75. * if there are no more screen share streams.
  76. *
  77. * @param {Store} store - The redux store.
  78. * @returns {void}
  79. */
  80. function _updateAutoPinnedParticipant({ dispatch, getState }) {
  81. const state = getState();
  82. const screenShares = state['features/video-layout'].screenShares;
  83. if (!screenShares) {
  84. return;
  85. }
  86. const latestScreenshareParticipantId
  87. = screenShares[screenShares.length - 1];
  88. if (latestScreenshareParticipantId) {
  89. dispatch(pinParticipant(latestScreenshareParticipantId));
  90. } else if (getPinnedParticipant(state['features/base/participants'])) {
  91. dispatch(pinParticipant(null));
  92. }
  93. }