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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import { CONFERENCE_FAILED } from '../base/conference';
  2. import { CONNECTION_ESTABLISHED, CONNECTION_FAILED } from '../base/connection';
  3. import {
  4. isFatalJitsiConnectionError,
  5. JitsiConferenceErrors,
  6. JitsiConnectionErrors
  7. } from '../base/lib-jitsi-meet';
  8. import { assign, ReducerRegistry, set } from '../base/redux';
  9. import {
  10. MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED,
  11. SUSPEND_DETECTED
  12. } from './actionTypes';
  13. const logger = require('jitsi-meet-logger').getLogger(__filename);
  14. /**
  15. * Reduces the Redux actions of the feature overlay.
  16. */
  17. ReducerRegistry.register('features/overlay', (state = {}, action) => {
  18. switch (action.type) {
  19. case CONFERENCE_FAILED:
  20. return _conferenceFailed(state, action);
  21. case CONNECTION_ESTABLISHED:
  22. return _connectionEstablished(state, action);
  23. case CONNECTION_FAILED:
  24. return _connectionFailed(state, action);
  25. case MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED:
  26. return _mediaPermissionPromptVisibilityChanged(state, action);
  27. case SUSPEND_DETECTED:
  28. return _suspendDetected(state, action);
  29. }
  30. return state;
  31. });
  32. /**
  33. * Reduces a specific Redux action CONFERENCE_FAILED of the feature overlay.
  34. *
  35. * @param {Object} state - The Redux state of the feature overlay.
  36. * @param {Action} action - The Redux action CONFERENCE_FAILED to reduce.
  37. * @returns {Object} The new state of the feature overlay after the reduction of
  38. * the specified action.
  39. * @private
  40. */
  41. function _conferenceFailed(state, { error, message }) {
  42. if (error === JitsiConferenceErrors.FOCUS_LEFT
  43. || error === JitsiConferenceErrors.VIDEOBRIDGE_NOT_AVAILABLE) {
  44. return assign(state, {
  45. haveToReload: true,
  46. isNetworkFailure: false,
  47. reason: message
  48. });
  49. }
  50. return state;
  51. }
  52. /**
  53. * Reduces a specific Redux action CONNECTION_ESTABLISHED of the feature
  54. * overlay.
  55. *
  56. * @param {Object} state - The Redux state of the feature overlay.
  57. * @returns {Object} The new state of the feature overlay after the reduction of
  58. * the specified action.
  59. * @private
  60. */
  61. function _connectionEstablished(state) {
  62. return set(state, 'connectionEstablished', true);
  63. }
  64. /**
  65. * Reduces a specific Redux action CONNECTION_FAILED of the feature overlay.
  66. *
  67. * @param {Object} state - The Redux state of the feature overlay.
  68. * @param {Action} action - The Redux action CONNECTION_FAILED to reduce.
  69. * @returns {Object} The new state of the feature overlay after the reduction of
  70. * the specified action.
  71. * @private
  72. */
  73. function _connectionFailed(state, { error, message }) {
  74. if (isFatalJitsiConnectionError(error)) {
  75. logger.error(`XMPP connection error: ${message}`);
  76. return assign(state, {
  77. haveToReload: true,
  78. // From all of the cases above only CONNECTION_DROPPED_ERROR is
  79. // considered a network type of failure.
  80. isNetworkFailure:
  81. error === JitsiConnectionErrors.CONNECTION_DROPPED_ERROR,
  82. reason: `xmpp-conn-dropped: ${message}`
  83. });
  84. }
  85. return state;
  86. }
  87. /**
  88. * Reduces a specific Redux action MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED of
  89. * the feature overlay.
  90. *
  91. * @param {Object} state - The Redux state of the feature overlay.
  92. * @param {Action} action - The Redux action to reduce.
  93. * @returns {Object} The new state of the feature overlay after the reduction of
  94. * the specified action.
  95. * @private
  96. */
  97. function _mediaPermissionPromptVisibilityChanged(state, action) {
  98. return assign(state, {
  99. browser: action.browser,
  100. isMediaPermissionPromptVisible: action.isVisible
  101. });
  102. }
  103. /**
  104. * Reduces a specific Redux action SUSPEND_DETECTED of the feature overlay.
  105. *
  106. * @param {Object} state - The Redux state of the feature overlay.
  107. * @returns {Object} The new state of the feature overlay after the reduction of
  108. * the specified action.
  109. * @private
  110. */
  111. function _suspendDetected(state) {
  112. return set(state, 'suspendDetected', true);
  113. }