您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

middleware.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // @flow
  2. import debounce from 'lodash/debounce';
  3. import { SET_ROOM } from '../../base/conference/actionTypes';
  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. }
  14. return next(action);
  15. });
  16. /**
  17. * Debounced sending of `readyToClose`.
  18. */
  19. const _sendReadyToClose = debounce(dispatch => {
  20. dispatch(readyToClose());
  21. }, 2500, { leading: true });
  22. /**
  23. * Notifies the feature base/conference that the action
  24. * {@code SET_ROOM} is being dispatched within a specific
  25. * redux store.
  26. *
  27. * @param {Store} store - The redux store in which the specified {@code action}
  28. * is being dispatched.
  29. * @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
  30. * specified {@code action} to the specified {@code store}.
  31. * @param {Action} action - The redux action {@code SET_ROOM}
  32. * which is being dispatched in the specified {@code store}.
  33. * @private
  34. * @returns {Object} The value returned by {@code next(action)}.
  35. */
  36. function _setRoom({ dispatch, getState }, next, action) {
  37. const { room: oldRoom } = getState()['features/base/conference'];
  38. const result = next(action);
  39. const { room: newRoom } = getState()['features/base/conference'];
  40. const isWelcomePageEnabled = isWelcomePageAppEnabled(getState());
  41. if (!oldRoom && newRoom) {
  42. navigateRoot(screen.conference.root);
  43. } else if (!newRoom) {
  44. if (isWelcomePageEnabled) {
  45. navigateRoot(screen.root);
  46. } else {
  47. // For JitsiSDK, WelcomePage is not available
  48. _sendReadyToClose(dispatch);
  49. }
  50. }
  51. return result;
  52. }