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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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);
  16. break;
  17. case SET_ROOM:
  18. _maybeStoreCurrentConference(store, 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({ dispatch, getState }, { room }) {
  34. if (room) {
  35. const { locationURL } = getState()['features/base/connection'];
  36. dispatch(storeCurrentConference(locationURL));
  37. }
  38. }
  39. /**
  40. * Updates the duration of the last conference stored in the list.
  41. *
  42. * @param {Store} store - The redux store.
  43. * @private
  44. * @returns {void}
  45. */
  46. function _updateConferenceDuration({ dispatch, getState }) {
  47. const { locationURL } = getState()['features/base/connection'];
  48. dispatch(updateConferenceDuration(locationURL));
  49. }