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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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);
  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);
  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, name } }) {
  49. if (name === JitsiConferenceErrors.FOCUS_LEFT
  50. || name === JitsiConferenceErrors.VIDEOBRIDGE_NOT_AVAILABLE) {
  51. return assign(state, {
  52. haveToReload: true,
  53. isNetworkFailure: false,
  54. // FIXME There is no message associated with CONFERENCE_FAILED at
  55. // the time of this writing. In jitsi-meet the action creator
  56. // conferenceFailed neither accepts an argument message nor defines
  57. // a property message on the error. In lib-jitsi-meet
  58. // CONFERENCE_FAILED emissions mostly do not provide a message with
  59. // the exception of at least one which provides an Error, not a
  60. // string.
  61. reason: message
  62. });
  63. }
  64. return state;
  65. }
  66. /**
  67. * Reduces a specific redux action CONNECTION_ESTABLISHED of the feature
  68. * overlay.
  69. *
  70. * @param {Object} state - The redux state of the feature overlay.
  71. * @private
  72. * @returns {Object} The new state of the feature overlay after the reduction of
  73. * the specified action.
  74. */
  75. function _connectionEstablished(state) {
  76. return set(state, 'connectionEstablished', true);
  77. }
  78. /**
  79. * Reduces a specific redux action CONNECTION_FAILED of the feature overlay.
  80. *
  81. * @param {Object} state - The redux state of the feature overlay.
  82. * @param {Action} action - The redux action CONNECTION_FAILED to reduce.
  83. * @private
  84. * @returns {Object} The new state of the feature overlay after the reduction of
  85. * the specified action.
  86. */
  87. function _connectionFailed(state, { error }) {
  88. if (isFatalJitsiConnectionError(error)) {
  89. const { message } = error;
  90. logger.error(`FATAL XMPP connection error: ${message}`);
  91. return assign(state, {
  92. haveToReload: true,
  93. // From all of the cases above only CONNECTION_DROPPED_ERROR is
  94. // considered a network type of failure.
  95. isNetworkFailure:
  96. error.name === JitsiConnectionErrors.CONNECTION_DROPPED_ERROR,
  97. reason: `xmpp-conn-dropped: ${message}`
  98. });
  99. }
  100. return state;
  101. }
  102. /**
  103. * Reduces a specific redux action CONNECTION_WILL_CONNECT in the feature
  104. * overlay. Clears the redux state related to the XMPP connection's status.
  105. *
  106. * @param {Object} state - The redux state of the feature overlay.
  107. * @param {Action} action - The redux action to reduce.
  108. * @private
  109. * @returns {Object} The new state of the feature overlay after reducing the
  110. * specified {@code action} in the feature overlay.
  111. */
  112. function _connectionWillConnect(
  113. state,
  114. action) { // eslint-disable-line no-unused-vars
  115. return assign(state, {
  116. connectionEstablished: undefined,
  117. haveToReload: undefined,
  118. isNetworkFailure: undefined,
  119. reason: undefined
  120. });
  121. }
  122. /**
  123. * Reduces a specific redux action MEDIA_PERMISSION_PROMPT_VISIBILITY_CHANGED of
  124. * the feature overlay.
  125. *
  126. * @param {Object} state - The redux state of the feature overlay.
  127. * @param {Action} action - The redux action to reduce.
  128. * @private
  129. * @returns {Object} The new state of the feature overlay after the reduction of
  130. * the specified action.
  131. */
  132. function _mediaPermissionPromptVisibilityChanged(
  133. state,
  134. { browser, isVisible }) {
  135. return assign(state, {
  136. browser,
  137. isMediaPermissionPromptVisible: isVisible
  138. });
  139. }
  140. /**
  141. * Reduces a specific redux action SUSPEND_DETECTED of the feature overlay.
  142. *
  143. * @param {Object} state - The redux state of the feature overlay.
  144. * @private
  145. * @returns {Object} The new state of the feature overlay after the reduction of
  146. * the specified action.
  147. */
  148. function _suspendDetected(state) {
  149. return set(state, 'suspendDetected', true);
  150. }