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

reducer.js 4.8KB

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