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

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