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.9KB

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