選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

middleware.js 2.8KB

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