Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

middleware.web.ts 4.5KB

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