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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. SUSPEND_DETECTED
  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 SUSPEND_DETECTED:
  26. return _suspendDetected(state);
  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. * Sets the {@code LoadConfigOverlay} overlay visible or not.
  50. *
  51. * @param {Object} state - The redux state of the feature overlay.
  52. * @param {boolean} show - Whether to show or not the overlay.
  53. * @returns {Object} The new state of the feature overlay after the reduction of
  54. * the specified action.
  55. */
  56. function _setShowLoadConfigOverlay(state, show) {
  57. return set(state, 'loadConfigOverlayVisible', show);
  58. }
  59. /**
  60. * Reduces a specific redux action {@code SET_FATAL_ERROR} of the feature
  61. * overlay.
  62. *
  63. * @param {Object} state - The redux state of the feature overlay.
  64. * @param {Error} fatalError - If the value is set it indicates that a fatal
  65. * error has occurred and that the reload screen is to be displayed.
  66. * @returns {Object}
  67. * @private
  68. */
  69. function _setFatalError(state, { fatalError }) {
  70. return set(state, 'fatalError', fatalError);
  71. }
  72. /**
  73. * Reduces a specific redux action SUSPEND_DETECTED of the feature overlay.
  74. *
  75. * @param {Object} state - The redux state of the feature overlay.
  76. * @private
  77. * @returns {Object} The new state of the feature overlay after the reduction of
  78. * the specified action.
  79. */
  80. function _suspendDetected(state) {
  81. return set(state, 'suspendDetected', true);
  82. }