Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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. 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/MiddlewareRegistry';
  24. // eslint-disable-next-line lines-around-comment
  25. // @ts-ignore
  26. import { isLocalVideoTrackDesktop } from '../tracks/functions';
  27. import { setLastN } from './actions';
  28. import { limitLastN } from './functions';
  29. import logger from './logger';
  30. /**
  31. * Updates the last N value in the conference based on the current state of the redux store.
  32. *
  33. * @param {Store} store - The redux store.
  34. * @private
  35. * @returns {void}
  36. */
  37. const _updateLastN = debounce(({ dispatch, getState }: IStore) => {
  38. const state = getState();
  39. const { conference } = state['features/base/conference'];
  40. if (!conference) {
  41. logger.debug('There is no active conference, not updating last N');
  42. return;
  43. }
  44. const { enabled: audioOnly } = state['features/base/audio-only'];
  45. const { appState } = state['features/background'] || {};
  46. const { enabled: filmStripEnabled } = state['features/filmstrip'];
  47. const config = state['features/base/config'];
  48. const { lastNLimits } = state['features/base/lastn'];
  49. const participantCount = getParticipantCount(state);
  50. const { carMode } = state['features/video-layout'];
  51. // Select the (initial) lastN value based on the following preference order.
  52. // 1. The last-n value from 'startLastN' if it is specified in config.js
  53. // 2. The last-n value from 'channelLastN' if specified in config.js.
  54. // 3. -1 as the default value.
  55. let lastNSelected = config.startLastN ?? (config.channelLastN ?? -1);
  56. // Apply last N limit based on the # of participants and config settings.
  57. // @ts-ignore
  58. const limitedLastN = limitLastN(participantCount, lastNLimits);
  59. if (limitedLastN !== undefined) {
  60. lastNSelected = lastNSelected === -1 ? limitedLastN : Math.min(limitedLastN, lastNSelected);
  61. }
  62. if (typeof appState !== 'undefined' && appState !== 'active') {
  63. lastNSelected = isLocalVideoTrackDesktop(state) ? 1 : 0;
  64. } else if (carMode) {
  65. lastNSelected = 0;
  66. } else if (audioOnly) {
  67. const { remoteScreenShares, tileViewEnabled } = state['features/video-layout'];
  68. const largeVideoParticipantId = state['features/large-video'].participantId;
  69. const largeVideoParticipant
  70. = largeVideoParticipantId ? getParticipantById(state, largeVideoParticipantId) : undefined;
  71. // Use tileViewEnabled state from redux here instead of determining if client should be in tile
  72. // view since we make an exception only for screenshare when in audio-only mode. If the user unpins
  73. // the screenshare, lastN will be set to 0 here. It will be set to 1 if screenshare has been auto pinned.
  74. if (!tileViewEnabled && largeVideoParticipant && !largeVideoParticipant.local) {
  75. lastNSelected = (remoteScreenShares || []).includes(largeVideoParticipantId ?? '') ? 1 : 0;
  76. } else {
  77. lastNSelected = 0;
  78. }
  79. } else if (!filmStripEnabled) {
  80. lastNSelected = 1;
  81. }
  82. dispatch(setLastN(lastNSelected));
  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 SCREEN_SHARE_REMOTE_PARTICIPANTS_UPDATED:
  93. case SELECT_LARGE_VIDEO_PARTICIPANT:
  94. case SET_AUDIO_ONLY:
  95. case SET_CAR_MODE:
  96. case SET_FILMSTRIP_ENABLED:
  97. case SET_TILE_VIEW:
  98. case VIRTUAL_SCREENSHARE_REMOTE_PARTICIPANTS_UPDATED:
  99. _updateLastN(store);
  100. break;
  101. }
  102. return result;
  103. });