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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // @flow
  2. import { appNavigate } from '../app';
  3. import {
  4. CONFERENCE_JOINED,
  5. KICKED_OUT,
  6. VIDEO_QUALITY_LEVELS,
  7. conferenceLeft,
  8. getCurrentConference,
  9. setPreferredVideoQuality
  10. } from '../base/conference';
  11. import { hideDialog, isDialogOpen } from '../base/dialog';
  12. import { setActiveModalId } from '../base/modal';
  13. import { pinParticipant } from '../base/participants';
  14. import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
  15. import { SET_REDUCED_UI } from '../base/responsive-ui';
  16. import { FeedbackDialog } from '../feedback';
  17. import { setFilmstripEnabled } from '../filmstrip';
  18. import { setToolboxEnabled } from '../toolbox';
  19. import { notifyKickedOut } from './actions';
  20. MiddlewareRegistry.register(store => next => action => {
  21. const result = next(action);
  22. switch (action.type) {
  23. case CONFERENCE_JOINED:
  24. case SET_REDUCED_UI: {
  25. const { dispatch, getState } = store;
  26. const state = getState();
  27. const { reducedUI } = state['features/base/responsive-ui'];
  28. dispatch(setToolboxEnabled(!reducedUI));
  29. dispatch(setFilmstripEnabled(!reducedUI));
  30. dispatch(
  31. setPreferredVideoQuality(
  32. reducedUI
  33. ? VIDEO_QUALITY_LEVELS.LOW
  34. : VIDEO_QUALITY_LEVELS.HIGH));
  35. break;
  36. }
  37. case KICKED_OUT: {
  38. const { dispatch } = store;
  39. dispatch(notifyKickedOut(
  40. action.participant,
  41. () => {
  42. dispatch(conferenceLeft(action.conference));
  43. dispatch(appNavigate(undefined));
  44. }
  45. ));
  46. break;
  47. }
  48. }
  49. return result;
  50. });
  51. /**
  52. * Set up state change listener to perform maintenance tasks when the conference
  53. * is left or failed, close all dialogs and unpin any pinned participants.
  54. */
  55. StateListenerRegistry.register(
  56. state => getCurrentConference(state),
  57. (conference, { dispatch, getState }, prevConference) => {
  58. const { authRequired, membersOnly, passwordRequired }
  59. = getState()['features/base/conference'];
  60. if (conference !== prevConference) {
  61. // Unpin participant, in order to avoid the local participant
  62. // remaining pinned, since it's not destroyed across runs.
  63. dispatch(pinParticipant(null));
  64. // XXX I wonder if there is a better way to do this. At this stage
  65. // we do know what dialogs we want to keep but the list of those
  66. // we want to hide is a lot longer. Thus we take a bit of a shortcut
  67. // and explicitly check.
  68. if (typeof authRequired === 'undefined'
  69. && typeof passwordRequired === 'undefined'
  70. && typeof membersOnly === 'undefined'
  71. && !isDialogOpen(getState(), FeedbackDialog)) {
  72. // Conference changed, left or failed... and there is no
  73. // pending authentication, nor feedback request, so close any
  74. // dialog we might have open.
  75. dispatch(hideDialog());
  76. }
  77. // We want to close all modals.
  78. dispatch(setActiveModalId());
  79. }
  80. });