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.

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