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.

reducer.js 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { VIDEO_QUALITY_LEVELS } from '../base/conference';
  2. import { SET_CONFIG } from '../base/config';
  3. import { ReducerRegistry, set } from '../base/redux';
  4. import { validateMinHeightForQualityLvl } from './functions';
  5. import logger from './logger';
  6. const DEFAULT_STATE = {
  7. minHeightForQualityLvl: new Map()
  8. };
  9. DEFAULT_STATE.minHeightForQualityLvl.set(360, VIDEO_QUALITY_LEVELS.STANDARD);
  10. DEFAULT_STATE.minHeightForQualityLvl.set(720, VIDEO_QUALITY_LEVELS.HIGH);
  11. ReducerRegistry.register('features/base/videoquality', (state = DEFAULT_STATE, action) => {
  12. switch (action.type) {
  13. case SET_CONFIG:
  14. return _setConfig(state, action);
  15. }
  16. return state;
  17. });
  18. /**
  19. * Extracts the height to quality level mapping from the new config.
  20. *
  21. * @param {Object} state - The Redux state of feature base/lastn.
  22. * @param {Action} action - The Redux action SET_CONFIG to reduce.
  23. * @private
  24. * @returns {Object} The new state after the reduction of the specified action.
  25. */
  26. function _setConfig(state, { config }) {
  27. const configuredMap = config?.videoQuality?.minHeightForQualityLvl;
  28. const convertedMap = validateMinHeightForQualityLvl(configuredMap);
  29. if (configuredMap && !convertedMap) {
  30. logger.error('Invalid config value videoQuality.minHeightForQualityLvl');
  31. }
  32. return convertedMap ? set(state, 'minHeightForQualityLvl', convertedMap) : state;
  33. }