You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

middleware.ts 3.3KB

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