選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

reducer.js 4.7KB

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