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.ts 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import { appNavigate } from '../app/actions';
  2. import { IStore } from '../app/types';
  3. import { CONFERENCE_JOINED, KICKED_OUT } from '../base/conference/actionTypes';
  4. import { conferenceLeft } from '../base/conference/actions';
  5. import { getCurrentConference } from '../base/conference/functions';
  6. import { hideDialog } from '../base/dialog/actions';
  7. import { isDialogOpen } from '../base/dialog/functions';
  8. import { pinParticipant } from '../base/participants/actions';
  9. import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
  10. import StateListenerRegistry from '../base/redux/StateListenerRegistry';
  11. import { SET_REDUCED_UI } from '../base/responsive-ui/actionTypes';
  12. // eslint-disable-next-line lines-around-comment
  13. // @ts-ignore
  14. import { FeedbackDialog } from '../feedback';
  15. import { setFilmstripEnabled } from '../filmstrip/actions';
  16. import { showSalesforceNotification } from '../salesforce/actions';
  17. import { setToolboxEnabled } from '../toolbox/actions';
  18. import { notifyKickedOut } from './actions';
  19. MiddlewareRegistry.register(store => next => action => {
  20. const result = next(action);
  21. switch (action.type) {
  22. case CONFERENCE_JOINED:
  23. _conferenceJoined(store);
  24. break;
  25. case SET_REDUCED_UI: {
  26. _setReducedUI(store);
  27. break;
  28. }
  29. case KICKED_OUT: {
  30. const { dispatch } = store;
  31. dispatch(notifyKickedOut(
  32. action.participant,
  33. () => {
  34. dispatch(conferenceLeft(action.conference));
  35. dispatch(appNavigate(undefined));
  36. }
  37. ));
  38. break;
  39. }
  40. }
  41. return result;
  42. });
  43. /**
  44. * Set up state change listener to perform maintenance tasks when the conference
  45. * is left or failed, close all dialogs and unpin any pinned participants.
  46. */
  47. StateListenerRegistry.register(
  48. state => getCurrentConference(state),
  49. (conference, { dispatch, getState }, prevConference) => {
  50. const { authRequired, membersOnly, passwordRequired }
  51. = getState()['features/base/conference'];
  52. if (conference !== prevConference) {
  53. // Unpin participant, in order to avoid the local participant
  54. // remaining pinned, since it's not destroyed across runs.
  55. dispatch(pinParticipant(null));
  56. // XXX I wonder if there is a better way to do this. At this stage
  57. // we do know what dialogs we want to keep but the list of those
  58. // we want to hide is a lot longer. Thus we take a bit of a shortcut
  59. // and explicitly check.
  60. if (typeof authRequired === 'undefined'
  61. && typeof passwordRequired === 'undefined'
  62. && typeof membersOnly === 'undefined'
  63. && !isDialogOpen(getState(), FeedbackDialog)) {
  64. // Conference changed, left or failed... and there is no
  65. // pending authentication, nor feedback request, so close any
  66. // dialog we might have open.
  67. dispatch(hideDialog());
  68. }
  69. }
  70. });
  71. /**
  72. * Configures the UI. In reduced UI mode some components will
  73. * be hidden if there is no space to render them.
  74. *
  75. * @param {Store} store - The redux store in which the specified {@code action}
  76. * is being dispatched.
  77. * @private
  78. * @returns {void}
  79. */
  80. function _setReducedUI({ dispatch, getState }: IStore) {
  81. const { reducedUI } = getState()['features/base/responsive-ui'];
  82. dispatch(setToolboxEnabled(!reducedUI));
  83. dispatch(setFilmstripEnabled(!reducedUI));
  84. }
  85. /**
  86. * Does extra sync up on properties that may need to be updated after the
  87. * conference was joined.
  88. *
  89. * @param {Store} store - The redux store in which the specified {@code action}
  90. * is being dispatched.
  91. * @private
  92. * @returns {void}
  93. */
  94. function _conferenceJoined({ dispatch, getState }: IStore) {
  95. _setReducedUI({
  96. dispatch,
  97. getState
  98. });
  99. dispatch(showSalesforceNotification());
  100. }