Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

middleware.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // @flow
  2. import debounce from 'lodash/debounce';
  3. import { SET_FILMSTRIP_ENABLED } from '../../filmstrip/actionTypes';
  4. import { SELECT_LARGE_VIDEO_PARTICIPANT } from '../../large-video/actionTypes';
  5. import { APP_STATE_CHANGED } from '../../mobile/background/actionTypes';
  6. import {
  7. SCREEN_SHARE_REMOTE_PARTICIPANTS_UPDATED,
  8. SET_CAR_MODE,
  9. SET_TILE_VIEW,
  10. VIRTUAL_SCREENSHARE_REMOTE_PARTICIPANTS_UPDATED
  11. } from '../../video-layout/actionTypes';
  12. import { SET_AUDIO_ONLY } from '../audio-only/actionTypes';
  13. import { CONFERENCE_JOINED } from '../conference/actionTypes';
  14. import {
  15. PARTICIPANT_JOINED,
  16. PARTICIPANT_KICKED,
  17. PARTICIPANT_LEFT
  18. } from '../participants/actionTypes';
  19. import {
  20. getParticipantById,
  21. getParticipantCount
  22. } from '../participants/functions';
  23. import { MiddlewareRegistry } from '../redux';
  24. import { isLocalVideoTrackDesktop } from '../tracks/functions';
  25. import { setLastN } from './actions';
  26. import { limitLastN } from './functions';
  27. import logger from './logger';
  28. /**
  29. * Updates the last N value in the conference based on the current state of the redux store.
  30. *
  31. * @param {Store} store - The redux store.
  32. * @private
  33. * @returns {void}
  34. */
  35. const _updateLastN = debounce(({ dispatch, getState }) => {
  36. const state = getState();
  37. const { conference } = state['features/base/conference'];
  38. if (!conference) {
  39. logger.debug('There is no active conference, not updating last N');
  40. return;
  41. }
  42. const { enabled: audioOnly } = state['features/base/audio-only'];
  43. const { appState } = state['features/background'] || {};
  44. const { enabled: filmStripEnabled } = state['features/filmstrip'];
  45. const config = state['features/base/config'];
  46. const { lastNLimits } = state['features/base/lastn'];
  47. const participantCount = getParticipantCount(state);
  48. const { carMode } = state['features/video-layout'];
  49. // Select the (initial) lastN value based on the following preference order.
  50. // 1. The last-n value from 'startLastN' if it is specified in config.js
  51. // 2. The last-n value from 'channelLastN' if specified in config.js.
  52. // 3. -1 as the default value.
  53. let lastNSelected = config.startLastN ?? (config.channelLastN ?? -1);
  54. // Apply last N limit based on the # of participants and config settings.
  55. const limitedLastN = limitLastN(participantCount, lastNLimits);
  56. if (limitedLastN !== undefined) {
  57. lastNSelected = lastNSelected === -1 ? limitedLastN : Math.min(limitedLastN, lastNSelected);
  58. }
  59. if (typeof appState !== 'undefined' && appState !== 'active') {
  60. lastNSelected = isLocalVideoTrackDesktop(state) ? 1 : 0;
  61. } else if (carMode) {
  62. lastNSelected = 0;
  63. } else if (audioOnly) {
  64. const { remoteScreenShares, tileViewEnabled } = state['features/video-layout'];
  65. const largeVideoParticipantId = state['features/large-video'].participantId;
  66. const largeVideoParticipant
  67. = largeVideoParticipantId ? getParticipantById(state, largeVideoParticipantId) : undefined;
  68. // Use tileViewEnabled state from redux here instead of determining if client should be in tile
  69. // view since we make an exception only for screenshare when in audio-only mode. If the user unpins
  70. // the screenshare, lastN will be set to 0 here. It will be set to 1 if screenshare has been auto pinned.
  71. if (!tileViewEnabled && largeVideoParticipant && !largeVideoParticipant.local) {
  72. lastNSelected = (remoteScreenShares || []).includes(largeVideoParticipantId) ? 1 : 0;
  73. } else {
  74. lastNSelected = 0;
  75. }
  76. } else if (!filmStripEnabled) {
  77. lastNSelected = 1;
  78. }
  79. dispatch(setLastN(lastNSelected));
  80. }, 1000); /* Don't send this more often than once a second. */
  81. MiddlewareRegistry.register(store => next => action => {
  82. const result = next(action);
  83. switch (action.type) {
  84. case APP_STATE_CHANGED:
  85. case CONFERENCE_JOINED:
  86. case PARTICIPANT_JOINED:
  87. case PARTICIPANT_KICKED:
  88. case PARTICIPANT_LEFT:
  89. case SCREEN_SHARE_REMOTE_PARTICIPANTS_UPDATED:
  90. case SELECT_LARGE_VIDEO_PARTICIPANT:
  91. case SET_AUDIO_ONLY:
  92. case SET_CAR_MODE:
  93. case SET_FILMSTRIP_ENABLED:
  94. case SET_TILE_VIEW:
  95. case VIRTUAL_SCREENSHARE_REMOTE_PARTICIPANTS_UPDATED:
  96. _updateLastN(store);
  97. break;
  98. }
  99. return result;
  100. });