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.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. // Only end the meeting if we are not already inside and trying to upgrade.
  47. if (authRequired && !conference) {
  48. dispatch(maybeRedirectToWelcomePage());
  49. }
  50. }
  51. break;
  52. }
  53. case CONFERENCE_FAILED: {
  54. const { error } = action;
  55. let recoverable;
  56. if (error.name === JitsiConferenceErrors.AUTHENTICATION_REQUIRED) {
  57. if (typeof error.recoverable === 'undefined') {
  58. error.recoverable = true;
  59. }
  60. recoverable = error.recoverable;
  61. }
  62. if (recoverable) {
  63. // we haven't migrated all the code from AuthHandler, and we need for now conference.js to trigger
  64. // the dialog to pass all required parameters to WaitForOwnerDialog
  65. // keep it commented, so we do not trigger sending iqs to jicofo twice
  66. // and showing the broken dialog with no handler
  67. // store.dispatch(waitForOwner());
  68. } else {
  69. store.dispatch(stopWaitForOwner());
  70. }
  71. break;
  72. }
  73. case CONFERENCE_JOINED:
  74. store.dispatch(stopWaitForOwner());
  75. store.dispatch(hideLoginDialog());
  76. break;
  77. case CONFERENCE_LEFT:
  78. store.dispatch(stopWaitForOwner());
  79. break;
  80. case CONNECTION_ESTABLISHED:
  81. store.dispatch(hideLoginDialog());
  82. break;
  83. case STOP_WAIT_FOR_OWNER:
  84. _clearExistingWaitForOwnerTimeout(store);
  85. store.dispatch(hideDialog(WaitForOwnerDialog));
  86. break;
  87. case UPGRADE_ROLE_FINISHED: {
  88. const { error, progress } = action;
  89. if (!error && progress === 1) {
  90. store.dispatch(hideLoginDialog());
  91. }
  92. break;
  93. }
  94. case WAIT_FOR_OWNER: {
  95. _clearExistingWaitForOwnerTimeout(store);
  96. const { handler, timeoutMs } = action;
  97. action.waitForOwnerTimeoutID = setTimeout(handler, timeoutMs);
  98. isDialogOpen(store, LoginDialog)
  99. || store.dispatch(openWaitForOwnerDialog());
  100. break;
  101. }
  102. }
  103. return next(action);
  104. });
  105. /**
  106. * Will clear the wait for conference owner timeout handler if any is currently
  107. * set.
  108. *
  109. * @param {Object} store - The redux store.
  110. * @returns {void}
  111. */
  112. function _clearExistingWaitForOwnerTimeout(
  113. { getState }: { getState: Function }) {
  114. const { waitForOwnerTimeoutID } = getState()['features/authentication'];
  115. waitForOwnerTimeoutID && clearTimeout(waitForOwnerTimeoutID);
  116. }
  117. /**
  118. * Checks if the cyclic "wait for conference owner" task is currently scheduled.
  119. *
  120. * @param {Object} store - The redux store.
  121. * @returns {void}
  122. */
  123. function _isWaitingForOwner({ getState }: { getState: Function }) {
  124. return getState()['features/authentication'].waitForOwnerTimeoutID;
  125. }