Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

middleware.ts 3.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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/mobile/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. // Because this is shared, on web appState is always undefined,
  40. // meaning that it is never active
  41. if (navigator.product === 'ReactNative' && (appState !== 'active' || carMode)) {
  42. lastNSelected = 0;
  43. } else if (audioOnly) {
  44. const { remoteScreenShares, tileViewEnabled } = state['features/video-layout'];
  45. const largeVideoParticipantId = state['features/large-video'].participantId;
  46. const largeVideoParticipant
  47. = largeVideoParticipantId ? getParticipantById(state, largeVideoParticipantId) : undefined;
  48. // Use tileViewEnabled state from redux here instead of determining if client should be in tile
  49. // view since we make an exception only for screenshare when in audio-only mode. If the user unpins
  50. // the screenshare, lastN will be set to 0 here. It will be set to 1 if screenshare has been auto pinned.
  51. if (!tileViewEnabled && largeVideoParticipant && !largeVideoParticipant.local) {
  52. lastNSelected = (remoteScreenShares || []).includes(largeVideoParticipantId ?? '') ? 1 : 0;
  53. } else {
  54. lastNSelected = 0;
  55. }
  56. } else if (!filmStripEnabled) {
  57. lastNSelected = 1;
  58. }
  59. const { lastN } = state['features/base/lastn'];
  60. if (lastN !== lastNSelected) {
  61. dispatch(setLastN(lastNSelected));
  62. }
  63. }, 1000); /* Don't send this more often than once a second. */
  64. MiddlewareRegistry.register(store => next => action => {
  65. const result = next(action);
  66. switch (action.type) {
  67. case APP_STATE_CHANGED:
  68. case CONFERENCE_JOINED:
  69. case SET_AUDIO_ONLY:
  70. case SET_CAR_MODE:
  71. case SET_FILMSTRIP_ENABLED:
  72. case VIRTUAL_SCREENSHARE_REMOTE_PARTICIPANTS_UPDATED:
  73. _updateLastN(store);
  74. break;
  75. }
  76. return result;
  77. });