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.

middleware.web.js 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // @flow
  2. import { maybeRedirectToWelcomePage } from '../app/actions';
  3. import {
  4. CONFERENCE_FAILED,
  5. CONFERENCE_JOINED,
  6. CONFERENCE_LEFT
  7. } from '../base/conference';
  8. import { CONNECTION_ESTABLISHED } from '../base/connection';
  9. import { hideDialog, isDialogOpen } from '../base/dialog';
  10. import {
  11. JitsiConferenceErrors
  12. } from '../base/lib-jitsi-meet';
  13. import { MiddlewareRegistry } from '../base/redux';
  14. import {
  15. CANCEL_LOGIN,
  16. STOP_WAIT_FOR_OWNER,
  17. UPGRADE_ROLE_FINISHED,
  18. WAIT_FOR_OWNER
  19. } from './actionTypes';
  20. import {
  21. hideLoginDialog,
  22. openWaitForOwnerDialog,
  23. stopWaitForOwner
  24. } from './actions.web';
  25. import { LoginDialog, WaitForOwnerDialog } from './components';
  26. /**
  27. * Middleware that captures connection or conference failed errors and controls
  28. * {@link WaitForOwnerDialog} and {@link LoginDialog}.
  29. *
  30. * FIXME Some of the complexity was introduced by the lack of dialog stacking.
  31. *
  32. * @param {Store} store - Redux store.
  33. * @returns {Function}
  34. */
  35. MiddlewareRegistry.register(store => next => action => {
  36. switch (action.type) {
  37. case CANCEL_LOGIN: {
  38. const { dispatch, getState } = store;
  39. if (!isDialogOpen(store, WaitForOwnerDialog)) {
  40. if (_isWaitingForOwner(store)) {
  41. dispatch(openWaitForOwnerDialog());
  42. return next(action);
  43. }
  44. dispatch(hideLoginDialog());
  45. const { authRequired, conference } = getState()['features/base/conference'];
  46. const { passwordRequired } = getState()['features/base/connection'];
  47. // Only end the meeting if we are not already inside and trying to upgrade.
  48. if ((authRequired && !conference) || passwordRequired) {
  49. dispatch(maybeRedirectToWelcomePage());
  50. }
  51. }
  52. break;
  53. }
  54. case CONFERENCE_FAILED: {
  55. const { error } = action;
  56. let recoverable;
  57. if (error.name === JitsiConferenceErrors.AUTHENTICATION_REQUIRED) {
  58. if (typeof error.recoverable === 'undefined') {
  59. error.recoverable = true;
  60. }
  61. recoverable = error.recoverable;
  62. }
  63. if (recoverable) {
  64. // we haven't migrated all the code from AuthHandler, and we need for now conference.js to trigger
  65. // the dialog to pass all required parameters to WaitForOwnerDialog
  66. // keep it commented, so we do not trigger sending iqs to jicofo twice
  67. // and showing the broken dialog with no handler
  68. // store.dispatch(waitForOwner());
  69. } else {
  70. store.dispatch(stopWaitForOwner());
  71. }
  72. break;
  73. }
  74. case CONFERENCE_JOINED:
  75. store.dispatch(stopWaitForOwner());
  76. store.dispatch(hideLoginDialog());
  77. break;
  78. case CONFERENCE_LEFT:
  79. store.dispatch(stopWaitForOwner());
  80. break;
  81. case CONNECTION_ESTABLISHED:
  82. store.dispatch(hideLoginDialog());
  83. break;
  84. case STOP_WAIT_FOR_OWNER:
  85. _clearExistingWaitForOwnerTimeout(store);
  86. store.dispatch(hideDialog(WaitForOwnerDialog));
  87. break;
  88. case UPGRADE_ROLE_FINISHED: {
  89. const { error, progress } = action;
  90. if (!error && progress === 1) {
  91. store.dispatch(hideLoginDialog());
  92. }
  93. break;
  94. }
  95. case WAIT_FOR_OWNER: {
  96. _clearExistingWaitForOwnerTimeout(store);
  97. const { handler, timeoutMs } = action;
  98. action.waitForOwnerTimeoutID = setTimeout(handler, timeoutMs);
  99. isDialogOpen(store, LoginDialog)
  100. || store.dispatch(openWaitForOwnerDialog());
  101. break;
  102. }
  103. }
  104. return next(action);
  105. });
  106. /**
  107. * Will clear the wait for conference owner timeout handler if any is currently
  108. * set.
  109. *
  110. * @param {Object} store - The redux store.
  111. * @returns {void}
  112. */
  113. function _clearExistingWaitForOwnerTimeout(
  114. { getState }: { getState: Function }) {
  115. const { waitForOwnerTimeoutID } = getState()['features/authentication'];
  116. waitForOwnerTimeoutID && clearTimeout(waitForOwnerTimeoutID);
  117. }
  118. /**
  119. * Checks if the cyclic "wait for conference owner" task is currently scheduled.
  120. *
  121. * @param {Object} store - The redux store.
  122. * @returns {void}
  123. */
  124. function _isWaitingForOwner({ getState }: { getState: Function }) {
  125. return getState()['features/authentication'].waitForOwnerTimeoutID;
  126. }