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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. if (typeof APP === 'object') {
  34. APP.API.notifyTileViewChanged(displayTileView);
  35. }
  36. }
  37. );
  38. /**
  39. * For auto-pin mode, listen for changes to the known media tracks and look
  40. * for updates to screen shares.
  41. */
  42. StateListenerRegistry.register(
  43. /* selector */ state => state['features/base/tracks'],
  44. /* listener */ (tracks, store) => {
  45. if (typeof interfaceConfig !== 'object'
  46. || !interfaceConfig.AUTO_PIN_LATEST_SCREEN_SHARE) {
  47. return;
  48. }
  49. const oldScreenSharesOrder
  50. = store.getState()['features/video-layout'].screenShares || [];
  51. const knownSharingParticipantIds = tracks.reduce((acc, track) => {
  52. if (track.mediaType === 'video' && track.videoType === 'desktop') {
  53. acc.push(track.participantId);
  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. }
  75. );
  76. /**
  77. * Private helper to automatically pin the latest screen share stream or unpin
  78. * if there are no more screen share streams.
  79. *
  80. * @param {Store} store - The redux store.
  81. * @returns {void}
  82. */
  83. function _updateAutoPinnedParticipant({ dispatch, getState }) {
  84. const state = getState();
  85. const screenShares = state['features/video-layout'].screenShares;
  86. if (!screenShares) {
  87. return;
  88. }
  89. const latestScreenshareParticipantId
  90. = screenShares[screenShares.length - 1];
  91. if (latestScreenshareParticipantId) {
  92. dispatch(pinParticipant(latestScreenshareParticipantId));
  93. } else if (getPinnedParticipant(state['features/base/participants'])) {
  94. dispatch(pinParticipant(null));
  95. }
  96. }