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.ts 4.5KB

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