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

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