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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. return _setConfig(store, next, action);
  24. }
  25. return next(action);
  26. });
  27. /**
  28. * Notifies the feature base/lib-jitsi-meet that the action SET_CONFIG is being
  29. * dispatched within a specific Redux store.
  30. *
  31. * @param {Store} store - The Redux store in which the specified action is being
  32. * dispatched.
  33. * @param {Dispatch} next - The Redux dispatch function to dispatch the
  34. * specified action to the specified store.
  35. * @param {Action} action - The Redux action SET_CONFIG which is being
  36. * dispatched in the specified store.
  37. * @private
  38. * @returns {Object} The new state that is the result of the reduction of the
  39. * specified action.
  40. */
  41. function _setConfig(store, next, action) {
  42. const { dispatch, getState } = store;
  43. const { initialized } = getState()['features/base/lib-jitsi-meet'];
  44. // XXX Since the config is changing, the library lib-jitsi-meet must be
  45. // initialized again with the new config. Consequntly, it may need to be
  46. // disposed of first.
  47. // TODO Currently, disposeLib actually does not dispose of lib-jitsi-meet
  48. // because lib-jitsi-meet does not implement such functionality.
  49. const disposeLibPromise
  50. = initialized ? dispatch(disposeLib()) : Promise.resolve();
  51. // Let the new config into the Redux store (because initLib will read it
  52. // from there).
  53. const nextState = next(action);
  54. disposeLibPromise.then(dispatch(initLib()));
  55. return nextState;
  56. }