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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { PARTICIPANT_LEFT } from '../participants';
  2. import { MiddlewareRegistry } from '../redux';
  3. import {
  4. disposeLib,
  5. initLib
  6. } from './actions';
  7. import { SET_CONFIG } from './actionTypes';
  8. /**
  9. * Middleware that captures PARTICIPANT_LEFT action for a local participant
  10. * (which signalizes that we finally left the app) and disposes lib-jitsi-meet.
  11. * Also captures SET_CONFIG action and disposes previous instance (if any) of
  12. * lib-jitsi-meet, and initializes a new one with new config.
  13. *
  14. * @param {Store} store - Redux store.
  15. * @returns {Function}
  16. */
  17. MiddlewareRegistry.register(store => next => action => {
  18. switch (action.type) {
  19. case PARTICIPANT_LEFT:
  20. if (action.participant.local) {
  21. store.dispatch(disposeLib());
  22. }
  23. break;
  24. case SET_CONFIG: {
  25. const { dispatch, getState } = store;
  26. const libInitialized = getState()['features/base/lib'].initialized;
  27. // XXX If we already have config, that means new config is coming, which
  28. // means that we should dispose instance of lib initialized with
  29. // previous config first.
  30. // TODO Currently 'disposeLib' actually does not dispose lib-jitsi-meet.
  31. // This functionality should be implemented.
  32. const promise = libInitialized
  33. ? dispatch(disposeLib())
  34. : Promise.resolve();
  35. promise
  36. .then(dispatch(initLib()));
  37. break;
  38. }
  39. }
  40. return next(action);
  41. });