您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

middleware.ts 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import debounce from 'lodash/debounce';
  2. import { IStore } from '../../app/types';
  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. SET_CAR_MODE,
  8. SET_TILE_VIEW,
  9. VIRTUAL_SCREENSHARE_REMOTE_PARTICIPANTS_UPDATED
  10. } from '../../video-layout/actionTypes';
  11. import { SET_AUDIO_ONLY } from '../audio-only/actionTypes';
  12. import { CONFERENCE_JOINED } from '../conference/actionTypes';
  13. import {
  14. PARTICIPANT_JOINED,
  15. PARTICIPANT_KICKED,
  16. PARTICIPANT_LEFT
  17. } from '../participants/actionTypes';
  18. import {
  19. getParticipantById,
  20. getParticipantCount
  21. } from '../participants/functions';
  22. import MiddlewareRegistry from '../redux/MiddlewareRegistry';
  23. import { isLocalVideoTrackDesktop } from '../tracks/functions';
  24. import { setLastN } from './actions';
  25. import { limitLastN } from './functions';
  26. import logger from './logger';
  27. /**
  28. * Updates the last N value in the conference based on the current state of the redux store.
  29. *
  30. * @param {Store} store - The redux store.
  31. * @private
  32. * @returns {void}
  33. */
  34. const _updateLastN = debounce(({ dispatch, getState }: IStore) => {
  35. const state = getState();
  36. const { conference } = state['features/base/conference'];
  37. if (!conference) {
  38. logger.debug('There is no active conference, not updating last N');
  39. return;
  40. }
  41. const { enabled: audioOnly } = state['features/base/audio-only'];
  42. const { appState } = state['features/background'] || {};
  43. const { enabled: filmStripEnabled } = state['features/filmstrip'];
  44. const config = state['features/base/config'];
  45. const { lastNLimits } = state['features/base/lastn'];
  46. const participantCount = getParticipantCount(state);
  47. const { carMode } = state['features/video-layout'];
  48. // Select the (initial) lastN value based on the following preference order.
  49. // 1. The last-n value from 'startLastN' if it is specified in config.js
  50. // 2. The last-n value from 'channelLastN' if specified in config.js.
  51. // 3. -1 as the default value.
  52. let lastNSelected = config.startLastN ?? (config.channelLastN ?? -1);
  53. // Apply last N limit based on the # of participants and config settings.
  54. // @ts-ignore
  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. const { lastN } = state['features/base/lastn'];
  80. if (lastN !== lastNSelected) {
  81. dispatch(setLastN(lastNSelected));
  82. }
  83. }, 1000); /* Don't send this more often than once a second. */
  84. MiddlewareRegistry.register(store => next => action => {
  85. const result = next(action);
  86. switch (action.type) {
  87. case APP_STATE_CHANGED:
  88. case CONFERENCE_JOINED:
  89. case PARTICIPANT_JOINED:
  90. case PARTICIPANT_KICKED:
  91. case PARTICIPANT_LEFT:
  92. case SELECT_LARGE_VIDEO_PARTICIPANT:
  93. case SET_AUDIO_ONLY:
  94. case SET_CAR_MODE:
  95. case SET_FILMSTRIP_ENABLED:
  96. case SET_TILE_VIEW:
  97. case VIRTUAL_SCREENSHARE_REMOTE_PARTICIPANTS_UPDATED:
  98. _updateLastN(store);
  99. break;
  100. }
  101. return result;
  102. });