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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import PersistenceRegistry from '../base/redux/PersistenceRegistry';
  2. import ReducerRegistry from '../base/redux/ReducerRegistry';
  3. import { BACKGROUND_ENABLED, SET_VIRTUAL_BACKGROUND } from './actionTypes';
  4. import { VIRTUAL_BACKGROUND_TYPE } from './constants';
  5. const STORE_NAME = 'features/virtual-background';
  6. export interface IVirtualBackground {
  7. backgroundEffectEnabled?: boolean;
  8. backgroundType?: string;
  9. blurValue?: number;
  10. selectedThumbnail?: string;
  11. virtualSource?: string;
  12. }
  13. /**
  14. * Reduces redux actions which activate/deactivate virtual background image, or
  15. * indicate if the virtual image background is activated/deactivated. The
  16. * backgroundEffectEnabled flag indicate if virtual background effect is activated.
  17. *
  18. * @param {State} state - The current redux state.
  19. * @param {Action} action - The redux action to reduce.
  20. * @param {string} action.type - The type of the redux action to reduce..
  21. * @returns {State} The next redux state that is the result of reducing the
  22. * specified action.
  23. */
  24. ReducerRegistry.register<IVirtualBackground>(STORE_NAME, (state = {}, action): IVirtualBackground => {
  25. const { virtualSource, backgroundEffectEnabled, blurValue, backgroundType, selectedThumbnail } = action;
  26. /**
  27. * Sets up the persistence of the feature {@code virtual-background}.
  28. */
  29. PersistenceRegistry.register(STORE_NAME, state.backgroundType !== VIRTUAL_BACKGROUND_TYPE.DESKTOP_SHARE);
  30. switch (action.type) {
  31. case SET_VIRTUAL_BACKGROUND: {
  32. return {
  33. ...state,
  34. virtualSource,
  35. blurValue,
  36. backgroundType,
  37. selectedThumbnail
  38. };
  39. }
  40. case BACKGROUND_ENABLED: {
  41. return {
  42. ...state,
  43. backgroundEffectEnabled
  44. };
  45. }
  46. }
  47. return state;
  48. });