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.native.ts 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { AnyAction } from 'redux';
  2. import { IStore } from '../app/types';
  3. import { hideDialog, openDialog } from '../base/dialog/actions';
  4. import { isDialogOpen } from '../base/dialog/functions';
  5. import { getLocalParticipant } from '../base/participants/functions';
  6. import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
  7. import {
  8. navigate
  9. } from '../mobile/navigation/components/conference/ConferenceNavigationContainerRef';
  10. import { screen } from '../mobile/navigation/routes';
  11. import { SET_WHITEBOARD_OPEN } from './actionTypes';
  12. import {
  13. notifyWhiteboardLimit,
  14. restrictWhiteboard
  15. } from './actions';
  16. import WhiteboardLimitDialog from './components/native/WhiteboardLimitDialog';
  17. import {
  18. generateCollabServerUrl,
  19. getCollabDetails,
  20. shouldEnforceUserLimit,
  21. shouldNotifyUserLimit
  22. } from './functions';
  23. import './middleware.any';
  24. /**
  25. * Middleware which intercepts whiteboard actions to handle changes to the related state.
  26. *
  27. * @param {Store} store - The redux store.
  28. * @returns {Function}
  29. */
  30. MiddlewareRegistry.register((store: IStore) => (next: Function) => (action: AnyAction) => {
  31. const { dispatch, getState } = store;
  32. const state = getState();
  33. switch (action.type) {
  34. case SET_WHITEBOARD_OPEN: {
  35. const { isOpen } = action;
  36. const enforceUserLimit = shouldEnforceUserLimit(state);
  37. const notifyUserLimit = shouldNotifyUserLimit(state);
  38. if (enforceUserLimit) {
  39. dispatch(restrictWhiteboard(false));
  40. dispatch(openDialog(WhiteboardLimitDialog));
  41. return next(action);
  42. }
  43. if (isOpen) {
  44. if (enforceUserLimit) {
  45. dispatch(restrictWhiteboard());
  46. return next(action);
  47. }
  48. if (notifyUserLimit) {
  49. dispatch(notifyWhiteboardLimit());
  50. }
  51. if (isDialogOpen(state, WhiteboardLimitDialog)) {
  52. dispatch(hideDialog(WhiteboardLimitDialog));
  53. }
  54. const collabDetails = getCollabDetails(state);
  55. const collabServerUrl = generateCollabServerUrl(state);
  56. const localParticipantName = getLocalParticipant(state)?.name;
  57. navigate(screen.conference.whiteboard, {
  58. collabDetails,
  59. collabServerUrl,
  60. localParticipantName
  61. });
  62. return next(action);
  63. }
  64. break;
  65. }
  66. }
  67. return next(action);
  68. });