您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

middleware.js 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_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 { getParticipantById } from '../participants/functions';
  9. import { MiddlewareRegistry } from '../redux';
  10. import logger from './logger';
  11. declare var APP: Object;
  12. MiddlewareRegistry.register(store => next => action => {
  13. const result = next(action);
  14. switch (action.type) {
  15. case APP_STATE_CHANGED:
  16. case CONFERENCE_JOINED:
  17. case SCREEN_SHARE_PARTICIPANTS_UPDATED:
  18. case SELECT_LARGE_VIDEO_PARTICIPANT:
  19. case SET_AUDIO_ONLY:
  20. case SET_FILMSTRIP_ENABLED:
  21. case SET_TILE_VIEW:
  22. _updateLastN(store);
  23. break;
  24. }
  25. return result;
  26. });
  27. /**
  28. * Updates the last N value in the conference based on the current state of the redux store.
  29. *
  30. * @param {Store} store - The redux store.
  31. * @private
  32. * @returns {void}
  33. */
  34. function _updateLastN({ getState }) {
  35. const state = getState();
  36. const { conference } = state['features/base/conference'];
  37. const { enabled: audioOnly } = state['features/base/audio-only'];
  38. const { appState } = state['features/background'];
  39. const { enabled: filmStripEnabled } = state['features/filmstrip'];
  40. const config = state['features/base/config'];
  41. if (!conference) {
  42. logger.debug('There is no active conference, not updating last N');
  43. return;
  44. }
  45. const defaultLastN = typeof config.channelLastN === 'undefined' ? -1 : config.channelLastN;
  46. let lastN = defaultLastN;
  47. if (appState !== 'active') {
  48. lastN = 0;
  49. } else if (audioOnly) {
  50. const { screenShares, tileViewEnabled } = state['features/video-layout'];
  51. const largeVideoParticipantId = state['features/large-video'].participantId;
  52. const largeVideoParticipant
  53. = largeVideoParticipantId ? getParticipantById(state, largeVideoParticipantId) : undefined;
  54. if (!tileViewEnabled && largeVideoParticipant && !largeVideoParticipant.local) {
  55. lastN = (screenShares || []).includes(largeVideoParticipantId) ? 1 : 0;
  56. } else {
  57. lastN = 0;
  58. }
  59. } else if (!filmStripEnabled) {
  60. lastN = 1;
  61. }
  62. if (conference.getLastN() === lastN) {
  63. return;
  64. }
  65. logger.info(`Setting last N to: ${lastN}`);
  66. try {
  67. conference.setLastN(lastN);
  68. } catch (err) {
  69. logger.error(`Failed to set lastN: ${err}`);
  70. }
  71. }