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

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