您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

middleware.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { PARTICIPANT_LEFT } from '../participants';
  2. import { MiddlewareRegistry } from '../redux';
  3. import { disposeLib, initLib } from './actions';
  4. import { SET_CONFIG } from './actionTypes';
  5. /**
  6. * Middleware that captures PARTICIPANT_LEFT action for a local participant
  7. * (which signalizes that we finally left the app) and disposes lib-jitsi-meet.
  8. * Also captures SET_CONFIG action and disposes previous instance (if any) of
  9. * lib-jitsi-meet, and initializes a new one with new config.
  10. *
  11. * @param {Store} store - Redux store.
  12. * @returns {Function}
  13. * @private
  14. */
  15. MiddlewareRegistry.register(store => next => action => {
  16. switch (action.type) {
  17. case PARTICIPANT_LEFT:
  18. action.participant.local && store.dispatch(disposeLib());
  19. break;
  20. case SET_CONFIG:
  21. return _setConfig(store, next, action);
  22. }
  23. return next(action);
  24. });
  25. /**
  26. * Notifies the feature base/lib-jitsi-meet that the action SET_CONFIG is being
  27. * dispatched within a specific Redux store.
  28. *
  29. * @param {Store} store - The Redux store in which the specified action is being
  30. * dispatched.
  31. * @param {Dispatch} next - The Redux dispatch function to dispatch the
  32. * specified action to the specified store.
  33. * @param {Action} action - The Redux action SET_CONFIG which is being
  34. * dispatched in the specified store.
  35. * @returns {Object} The new state that is the result of the reduction of the
  36. * specified action.
  37. * @private
  38. */
  39. function _setConfig(store, next, action) {
  40. const { dispatch, getState } = store;
  41. const { initialized } = getState()['features/base/lib-jitsi-meet'];
  42. // XXX Since the config is changing, the library lib-jitsi-meet must be
  43. // initialized again with the new config. Consequntly, it may need to be
  44. // disposed of first.
  45. // TODO Currently, disposeLib actually does not dispose of lib-jitsi-meet
  46. // because lib-jitsi-meet does not implement such functionality.
  47. const disposeLibPromise
  48. = initialized ? dispatch(disposeLib()) : Promise.resolve();
  49. // Let the new config into the Redux store (because initLib will read it
  50. // from there).
  51. const nextState = next(action);
  52. disposeLibPromise.then(dispatch(initLib()));
  53. return nextState;
  54. }