Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

subscriber.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. // TODO: interfaceConfig should be in redux so we didn't have to do this.
  17. const AUTO_PIN_LATEST_SCREEN_SHARE
  18. = typeof interfaceConfig === 'object' ? interfaceConfig.AUTO_PIN_LATEST_SCREEN_SHARE : 'remote-only';
  19. /**
  20. * StateListenerRegistry provides a reliable way of detecting changes to
  21. * preferred layout state and dispatching additional actions.
  22. */
  23. StateListenerRegistry.register(
  24. /* selector */ state => shouldDisplayTileView(state),
  25. /* listener */ (displayTileView, store) => {
  26. const { dispatch } = store;
  27. dispatch(selectParticipant());
  28. if (!displayTileView) {
  29. dispatch(
  30. setMaxReceiverVideoQuality(VIDEO_QUALITY_LEVELS.HIGH));
  31. if (AUTO_PIN_LATEST_SCREEN_SHARE) {
  32. _updateAutoPinnedParticipant(store);
  33. }
  34. }
  35. }
  36. );
  37. /**
  38. * For auto-pin mode, listen for changes to the known media tracks and look
  39. * for updates to screen shares.
  40. */
  41. StateListenerRegistry.register(
  42. /* selector */ state => state['features/base/tracks'],
  43. /* listener */ (tracks, store) => {
  44. if (!AUTO_PIN_LATEST_SCREEN_SHARE) {
  45. return;
  46. }
  47. const oldScreenSharesOrder
  48. = store.getState()['features/video-layout'].screenShares || [];
  49. const knownSharingParticipantIds = tracks.reduce((acc, track) => {
  50. if (track.mediaType === 'video' && track.videoType === 'desktop') {
  51. const skipTrack
  52. = AUTO_PIN_LATEST_SCREEN_SHARE === 'remote-only' && track.local;
  53. if (!skipTrack) {
  54. acc.push(track.participantId);
  55. }
  56. }
  57. return acc;
  58. }, []);
  59. // Filter out any participants which are no longer screen sharing
  60. // by looping through the known sharing participants and removing any
  61. // participant IDs which are no longer sharing.
  62. const newScreenSharesOrder = oldScreenSharesOrder.filter(
  63. participantId => knownSharingParticipantIds.includes(participantId));
  64. // Make sure all new sharing participant get added to the end of the
  65. // known screen shares.
  66. knownSharingParticipantIds.forEach(participantId => {
  67. if (!newScreenSharesOrder.includes(participantId)) {
  68. newScreenSharesOrder.push(participantId);
  69. }
  70. });
  71. if (!equals(oldScreenSharesOrder, newScreenSharesOrder)) {
  72. store.dispatch(
  73. setParticipantsWithScreenShare(newScreenSharesOrder));
  74. _updateAutoPinnedParticipant(store);
  75. }
  76. }
  77. );
  78. /**
  79. * Private helper to automatically pin the latest screen share stream or unpin
  80. * if there are no more screen share streams.
  81. *
  82. * @param {Store} store - The redux store.
  83. * @returns {void}
  84. */
  85. function _updateAutoPinnedParticipant({ dispatch, getState }) {
  86. const state = getState();
  87. const screenShares = state['features/video-layout'].screenShares;
  88. if (!screenShares) {
  89. return;
  90. }
  91. const latestScreenshareParticipantId
  92. = screenShares[screenShares.length - 1];
  93. if (latestScreenshareParticipantId) {
  94. dispatch(pinParticipant(latestScreenshareParticipantId));
  95. } else if (getPinnedParticipant(state['features/base/participants'])) {
  96. dispatch(pinParticipant(null));
  97. }
  98. }