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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. import { CONFIG_WILL_LOAD, LOAD_CONFIG_ERROR, SET_CONFIG } from '../base/config/actionTypes';
  2. import ReducerRegistry from '../base/redux/ReducerRegistry';
  3. import { assign, set } from '../base/redux/functions';
  4. import {
  5. MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED,
  6. SET_FATAL_ERROR,
  7. TOGGLE_SLOW_GUM_OVERLAY
  8. } from './actionTypes';
  9. export interface IOverlayState {
  10. browser?: string;
  11. fatalError?: Error;
  12. isMediaPermissionPromptVisible?: boolean;
  13. isSlowGUMOverlayVisible?: boolean;
  14. loadConfigOverlayVisible?: boolean;
  15. }
  16. /**
  17. * Reduces the redux actions of the feature overlay.
  18. *
  19. * FIXME: these pieces of state should probably be in a different place.
  20. */
  21. ReducerRegistry.register<IOverlayState>('features/overlay', (state = {}, action): IOverlayState => {
  22. switch (action.type) {
  23. case CONFIG_WILL_LOAD:
  24. return _setShowLoadConfigOverlay(state, Boolean(action.room));
  25. case LOAD_CONFIG_ERROR:
  26. case SET_CONFIG:
  27. return _setShowLoadConfigOverlay(state, false);
  28. case MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED:
  29. return _mediaPermissionPromptVisibilityChanged(state, action);
  30. case SET_FATAL_ERROR:
  31. return _setFatalError(state, action);
  32. case TOGGLE_SLOW_GUM_OVERLAY:
  33. return _toggleSlowGUMOverlay(state, action);
  34. }
  35. return state;
  36. });
  37. /**
  38. * Reduces a specific redux action MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED of
  39. * the feature overlay.
  40. *
  41. * @param {Object} state - The redux state of the feature overlay.
  42. * @param {Action} action - The redux action to reduce.
  43. * @private
  44. * @returns {Object} The new state of the feature overlay after the reduction of
  45. * the specified action.
  46. */
  47. function _mediaPermissionPromptVisibilityChanged(
  48. state: IOverlayState,
  49. { browser, isVisible }: { browser?: string; isVisible?: boolean; }) {
  50. return assign(state, {
  51. browser,
  52. isMediaPermissionPromptVisible: isVisible
  53. });
  54. }
  55. /**
  56. * Reduces a specific redux action TOGGLE_SLOW_GUM_OVERLAY of
  57. * the feature overlay.
  58. *
  59. * @param {Object} state - The redux state of the feature overlay.
  60. * @param {Action} action - The redux action to reduce.
  61. * @private
  62. * @returns {Object} The new state of the feature overlay after the reduction of
  63. * the specified action.
  64. */
  65. function _toggleSlowGUMOverlay(
  66. state: IOverlayState,
  67. { isVisible }: { isVisible?: boolean; }) {
  68. return assign(state, {
  69. isSlowGUMOverlayVisible: isVisible
  70. });
  71. }
  72. /**
  73. * Sets the {@code LoadConfigOverlay} overlay visible or not.
  74. *
  75. * @param {Object} state - The redux state of the feature overlay.
  76. * @param {boolean} show - Whether to show or not the overlay.
  77. * @returns {Object} The new state of the feature overlay after the reduction of
  78. * the specified action.
  79. */
  80. function _setShowLoadConfigOverlay(state: IOverlayState, show?: boolean) {
  81. return set(state, 'loadConfigOverlayVisible', show);
  82. }
  83. /**
  84. * Reduces a specific redux action {@code SET_FATAL_ERROR} of the feature
  85. * overlay.
  86. *
  87. * @param {Object} state - The redux state of the feature overlay.
  88. * @param {Error} fatalError - If the value is set it indicates that a fatal
  89. * error has occurred and that the reload screen is to be displayed.
  90. * @returns {Object}
  91. * @private
  92. */
  93. function _setFatalError(state: IOverlayState, { fatalError }: { fatalError?: Error; }) {
  94. return set(state, 'fatalError', fatalError);
  95. }