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.js 4.0KB

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