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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 }) {
  80. if (isFatalJitsiConnectionError(error)) {
  81. const { message } = error;
  82. logger.error(`FATAL XMPP connection error: ${message}`);
  83. return assign(state, {
  84. haveToReload: true,
  85. // From all of the cases above only CONNECTION_DROPPED_ERROR is
  86. // considered a network type of failure.
  87. isNetworkFailure:
  88. error.name === JitsiConnectionErrors.CONNECTION_DROPPED_ERROR,
  89. reason: `xmpp-conn-dropped: ${message}`
  90. });
  91. }
  92. return state;
  93. }
  94. /**
  95. * Reduces a specific redux action CONNECTION_WILL_CONNECT in the feature
  96. * overlay. Clears the redux state related to the XMPP connection's status.
  97. *
  98. * @param {Object} state - The redux state of the feature overlay.
  99. * @param {Action} action - The redux action to reduce.
  100. * @private
  101. * @returns {Object} The new state of the feature overlay after reducing the
  102. * specified {@code action} in the feature overlay.
  103. */
  104. function _connectionWillConnect(
  105. state,
  106. action) { // eslint-disable-line no-unused-vars
  107. return assign(state, {
  108. connectionEstablished: undefined,
  109. haveToReload: undefined,
  110. isNetworkFailure: undefined,
  111. reason: undefined
  112. });
  113. }
  114. /**
  115. * Reduces a specific redux action MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED of
  116. * the feature overlay.
  117. *
  118. * @param {Object} state - The redux state of the feature overlay.
  119. * @param {Action} action - The redux action to reduce.
  120. * @private
  121. * @returns {Object} The new state of the feature overlay after the reduction of
  122. * the specified action.
  123. */
  124. function _mediaPermissionPromptVisibilityChanged(state, action) {
  125. return assign(state, {
  126. browser: action.browser,
  127. isMediaPermissionPromptVisible: action.isVisible
  128. });
  129. }
  130. /**
  131. * Reduces a specific redux action SUSPEND_DETECTED of the feature overlay.
  132. *
  133. * @param {Object} state - The redux state of the feature overlay.
  134. * @private
  135. * @returns {Object} The new state of the feature overlay after the reduction of
  136. * the specified action.
  137. */
  138. function _suspendDetected(state) {
  139. return set(state, 'suspendDetected', true);
  140. }