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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // @flow
  2. import { notifyKickedOut } from './actions';
  3. import { appNavigate } from '../app';
  4. import {
  5. CONFERENCE_JOINED,
  6. KICKED_OUT,
  7. VIDEO_QUALITY_LEVELS,
  8. conferenceLeft,
  9. getCurrentConference,
  10. setPreferredVideoQuality
  11. } from '../base/conference';
  12. import { hideDialog, isDialogOpen } from '../base/dialog';
  13. import { setActiveModalId } from '../base/modal';
  14. import { pinParticipant } from '../base/participants';
  15. import { SET_REDUCED_UI } from '../base/responsive-ui';
  16. import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
  17. import { FeedbackDialog } from '../feedback';
  18. import { setFilmstripEnabled } from '../filmstrip';
  19. import { setToolboxEnabled } from '../toolbox';
  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, 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. && !isDialogOpen(getState(), FeedbackDialog)) {
  71. // Conference changed, left or failed... and there is no
  72. // pending authentication, nor feedback request, so close any
  73. // dialog we might have open.
  74. dispatch(hideDialog());
  75. }
  76. // We want to close all modals.
  77. dispatch(setActiveModalId());
  78. }
  79. });