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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // @flow
  2. import { CONFERENCE_WILL_LEAVE, SET_ROOM } from '../base/conference';
  3. import { MiddlewareRegistry } from '../base/redux';
  4. import { storeCurrentConference, updateConferenceDuration } from './actions';
  5. /**
  6. * Middleware that captures joined rooms so they can be saved into
  7. * {@code window.localStorage}.
  8. *
  9. * @param {Store} store - The redux store.
  10. * @returns {Function}
  11. */
  12. MiddlewareRegistry.register(store => next => action => {
  13. switch (action.type) {
  14. case CONFERENCE_WILL_LEAVE:
  15. _updateConferenceDuration(store, next);
  16. break;
  17. case SET_ROOM:
  18. _maybeStoreCurrentConference(store, next, action);
  19. break;
  20. }
  21. return next(action);
  22. });
  23. /**
  24. * Checks if there is a current conference (upon SET_ROOM action), and saves it
  25. * if necessary.
  26. *
  27. * @param {Store} store - The redux store.
  28. * @param {Dispatch} next - The redux {@code dispatch} function.
  29. * @param {Action} action - The redux action.
  30. * @private
  31. * @returns {void}
  32. */
  33. function _maybeStoreCurrentConference(store, next, action) {
  34. const { locationURL } = store.getState()['features/base/connection'];
  35. const { room } = action;
  36. if (room) {
  37. next(storeCurrentConference(locationURL));
  38. }
  39. }
  40. /**
  41. * Updates the duration of the last conference stored in the list.
  42. *
  43. * @param {Store} store - The redux store.
  44. * @param {Dispatch} next - The redux {@code dispatch} function.
  45. * @param {Action} action - The redux action.
  46. * @private
  47. * @returns {void}
  48. */
  49. function _updateConferenceDuration(store, next) {
  50. const { locationURL } = store.getState()['features/base/connection'];
  51. next(updateConferenceDuration(locationURL));
  52. }