您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

reducer.js 4.2KB

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