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

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