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.js 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import debounce from 'lodash/debounce';
  2. import { CONFERENCE_FAILED, SET_ROOM } from '../../base/conference/actionTypes';
  3. import { JitsiConferenceErrors } from '../../base/lib-jitsi-meet';
  4. import { MiddlewareRegistry } from '../../base/redux';
  5. import { readyToClose } from '../external-api/actions';
  6. import { isWelcomePageAppEnabled } from './components/welcome/functions';
  7. import { navigateRoot } from './rootNavigationContainerRef';
  8. import { screen } from './routes';
  9. MiddlewareRegistry.register(store => next => action => {
  10. switch (action.type) {
  11. case SET_ROOM:
  12. return _setRoom(store, next, action);
  13. case CONFERENCE_FAILED:
  14. return _conferenceFailed(store, next, action);
  15. }
  16. return next(action);
  17. });
  18. /**
  19. * Debounced sending of `readyToClose`.
  20. */
  21. const _sendReadyToClose = debounce(dispatch => {
  22. dispatch(readyToClose());
  23. }, 2500, { leading: true });
  24. /**
  25. * Notifies the feature base/conference that the action
  26. * {@code SET_ROOM} is being dispatched within a specific
  27. * redux store.
  28. *
  29. * @param {Store} store - The redux store in which the specified {@code action}
  30. * is being dispatched.
  31. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  32. * specified {@code action} to the specified {@code store}.
  33. * @param {Action} action - The redux action {@code SET_ROOM}
  34. * which is being dispatched in the specified {@code store}.
  35. * @private
  36. * @returns {Object} The value returned by {@code next(action)}.
  37. */
  38. function _setRoom({ dispatch, getState }, next, action) {
  39. const { room: oldRoom } = getState()['features/base/conference'];
  40. const result = next(action);
  41. const { room: newRoom } = getState()['features/base/conference'];
  42. const isWelcomePageEnabled = isWelcomePageAppEnabled(getState());
  43. if (!oldRoom && newRoom) {
  44. navigateRoot(screen.conference.root);
  45. } else if (!newRoom) {
  46. if (isWelcomePageEnabled) {
  47. navigateRoot(screen.root);
  48. } else {
  49. // For JitsiSDK, WelcomePage is not available
  50. _sendReadyToClose(dispatch);
  51. }
  52. }
  53. return result;
  54. }
  55. /**
  56. * Function to handle the conference failed event and navigate the user to the lobby screen
  57. * based on the failure reason.
  58. *
  59. * @param {Object} store - The Redux store.
  60. * @param {Function} next - The Redux next function.
  61. * @param {Object} action - The Redux action.
  62. * @returns {Object}
  63. */
  64. function _conferenceFailed({ dispatch, getState }, next, action) {
  65. const state = getState();
  66. const isWelcomePageEnabled = isWelcomePageAppEnabled(state);
  67. const { error } = action;
  68. // We need to cover the case where knocking participant
  69. // is rejected from entering the conference
  70. if (error.name === JitsiConferenceErrors.CONFERENCE_ACCESS_DENIED) {
  71. if (isWelcomePageEnabled) {
  72. navigateRoot(screen.root);
  73. } else {
  74. // For JitsiSDK, WelcomePage is not available
  75. _sendReadyToClose(dispatch);
  76. }
  77. }
  78. return next(action);
  79. }