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

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