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

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. action.participant.local && store.dispatch(disposeLib());
  21. break;
  22. case SET_CONFIG: {
  23. const { dispatch, getState } = store;
  24. const initialized
  25. = getState()['features/base/lib-jitsi-meet'].initialized;
  26. // XXX If we already have config, that means new config is coming, which
  27. // means that we should dispose instance of lib initialized with
  28. // previous config first.
  29. // TODO Currently 'disposeLib' actually does not dispose lib-jitsi-meet.
  30. // This functionality should be implemented.
  31. const promise
  32. = initialized ? dispatch(disposeLib()) : Promise.resolve();
  33. promise.then(dispatch(initLib()));
  34. break;
  35. }
  36. }
  37. return next(action);
  38. });