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

middleware.js 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. FAKE_SCREEN_SHARE_REMOTE_PARTICIPANTS_UPDATED,
  8. SCREEN_SHARE_REMOTE_PARTICIPANTS_UPDATED,
  9. SET_TILE_VIEW
  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';
  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 }) => {
  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. // Select the (initial) lastN value based on the following preference order.
  48. // 1. The last-n value from 'startLastN' if it is specified in config.js
  49. // 2. The last-n value from 'channelLastN' if specified in config.js.
  50. // 3. -1 as the default value.
  51. let lastNSelected = config.startLastN ?? (config.channelLastN ?? -1);
  52. // Apply last N limit based on the # of participants and config settings.
  53. const limitedLastN = limitLastN(participantCount, lastNLimits);
  54. if (limitedLastN !== undefined) {
  55. lastNSelected = lastNSelected === -1 ? limitedLastN : Math.min(limitedLastN, lastNSelected);
  56. }
  57. if (typeof appState !== 'undefined' && appState !== 'active') {
  58. lastNSelected = isLocalVideoTrackDesktop(state) ? 1 : 0;
  59. } else if (audioOnly) {
  60. const { remoteScreenShares, tileViewEnabled } = state['features/video-layout'];
  61. const largeVideoParticipantId = state['features/large-video'].participantId;
  62. const largeVideoParticipant
  63. = largeVideoParticipantId ? getParticipantById(state, largeVideoParticipantId) : undefined;
  64. // Use tileViewEnabled state from redux here instead of determining if client should be in tile
  65. // view since we make an exception only for screenshare when in audio-only mode. If the user unpins
  66. // the screenshare, lastN will be set to 0 here. It will be set to 1 if screenshare has been auto pinned.
  67. if (!tileViewEnabled && largeVideoParticipant && !largeVideoParticipant.local) {
  68. lastNSelected = (remoteScreenShares || []).includes(largeVideoParticipantId) ? 1 : 0;
  69. } else {
  70. lastNSelected = 0;
  71. }
  72. } else if (!filmStripEnabled) {
  73. lastNSelected = 1;
  74. }
  75. dispatch(setLastN(lastNSelected));
  76. }, 1000); /* Don't send this more often than once a second. */
  77. MiddlewareRegistry.register(store => next => action => {
  78. const result = next(action);
  79. switch (action.type) {
  80. case APP_STATE_CHANGED:
  81. case CONFERENCE_JOINED:
  82. case FAKE_SCREEN_SHARE_REMOTE_PARTICIPANTS_UPDATED:
  83. case PARTICIPANT_JOINED:
  84. case PARTICIPANT_KICKED:
  85. case PARTICIPANT_LEFT:
  86. case SCREEN_SHARE_REMOTE_PARTICIPANTS_UPDATED:
  87. case SELECT_LARGE_VIDEO_PARTICIPANT:
  88. case SET_AUDIO_ONLY:
  89. case SET_FILMSTRIP_ENABLED:
  90. case SET_TILE_VIEW:
  91. _updateLastN(store);
  92. break;
  93. }
  94. return result;
  95. });