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

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