Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. WAIT_FOR_OWNER
  18. } from './actionTypes';
  19. import {
  20. hideLoginDialog,
  21. openWaitForOwnerDialog,
  22. stopWaitForOwner,
  23. waitForOwner
  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. if (!isDialogOpen(store, WaitForOwnerDialog)) {
  39. if (_isWaitingForOwner(store)) {
  40. store.dispatch(openWaitForOwnerDialog());
  41. return next(action);
  42. }
  43. store.dispatch(hideLoginDialog());
  44. store.dispatch(maybeRedirectToWelcomePage());
  45. }
  46. break;
  47. }
  48. case CONFERENCE_FAILED: {
  49. const { error } = action;
  50. let recoverable;
  51. if (error.name === JitsiConferenceErrors.AUTHENTICATION_REQUIRED) {
  52. if (typeof error.recoverable === 'undefined') {
  53. error.recoverable = true;
  54. }
  55. recoverable = error.recoverable;
  56. }
  57. if (recoverable) {
  58. store.dispatch(waitForOwner());
  59. } else {
  60. store.dispatch(stopWaitForOwner());
  61. }
  62. break;
  63. }
  64. case CONFERENCE_JOINED:
  65. if (_isWaitingForOwner(store)) {
  66. store.dispatch(stopWaitForOwner());
  67. }
  68. store.dispatch(hideLoginDialog());
  69. break;
  70. case CONFERENCE_LEFT:
  71. store.dispatch(stopWaitForOwner());
  72. break;
  73. case CONNECTION_ESTABLISHED:
  74. store.dispatch(hideLoginDialog());
  75. break;
  76. case STOP_WAIT_FOR_OWNER:
  77. _clearExistingWaitForOwnerTimeout(store);
  78. store.dispatch(hideDialog(WaitForOwnerDialog));
  79. break;
  80. case WAIT_FOR_OWNER: {
  81. _clearExistingWaitForOwnerTimeout(store);
  82. const { handler, timeoutMs } = action;
  83. action.waitForOwnerTimeoutID = setTimeout(handler, timeoutMs);
  84. isDialogOpen(store, LoginDialog)
  85. || store.dispatch(openWaitForOwnerDialog());
  86. break;
  87. }
  88. }
  89. return next(action);
  90. });
  91. /**
  92. * Will clear the wait for conference owner timeout handler if any is currently
  93. * set.
  94. *
  95. * @param {Object} store - The redux store.
  96. * @returns {void}
  97. */
  98. function _clearExistingWaitForOwnerTimeout(
  99. { getState }: { getState: Function }) {
  100. const { waitForOwnerTimeoutID } = getState()['features/authentication'];
  101. waitForOwnerTimeoutID && clearTimeout(waitForOwnerTimeoutID);
  102. }
  103. /**
  104. * Checks if the cyclic "wait for conference owner" task is currently scheduled.
  105. *
  106. * @param {Object} store - The redux store.
  107. * @returns {void}
  108. */
  109. function _isWaitingForOwner({ getState }: { getState: Function }) {
  110. return getState()['features/authentication'].waitForOwnerTimeoutID;
  111. }