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

middleware.js 4.1KB

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