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 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 { setToolboxEnabled } from '../toolbox/actions';
  16. import { notifyKickedOut } from './actions';
  17. MiddlewareRegistry.register(store => next => action => {
  18. const result = next(action);
  19. switch (action.type) {
  20. case CONFERENCE_JOINED:
  21. case SET_REDUCED_UI: {
  22. const { dispatch, getState } = store;
  23. const state = getState();
  24. const { reducedUI } = state['features/base/responsive-ui'];
  25. dispatch(setToolboxEnabled(!reducedUI));
  26. dispatch(setFilmstripEnabled(!reducedUI));
  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. });