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 3.8KB

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