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

middleware.js 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // @flow
  2. import UIEvents from '../../../service/UI/UIEvents';
  3. import { getCurrentConference } from '../base/conference';
  4. import { CONFERENCE_JOIN_IN_PROGRESS } from '../base/conference/actionTypes';
  5. import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
  6. import { TOGGLE_DOCUMENT_EDITING } from './actionTypes';
  7. import { setDocumentUrl } from './actions';
  8. declare var APP: Object;
  9. const ETHERPAD_COMMAND = 'etherpad';
  10. /**
  11. * Middleware that captures actions related to collaborative document editing
  12. * and notifies components not hooked into redux.
  13. *
  14. * @param {Store} store - The redux store.
  15. * @returns {Function}
  16. */
  17. // eslint-disable-next-line no-unused-vars
  18. MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
  19. switch (action.type) {
  20. case CONFERENCE_JOIN_IN_PROGRESS: {
  21. const { conference } = action;
  22. conference.addCommandListener(ETHERPAD_COMMAND,
  23. ({ value }) => {
  24. let url;
  25. const { etherpad_base: etherpadBase } = getState()['features/base/config'];
  26. if (etherpadBase) {
  27. url = new URL(value, etherpadBase).toString();
  28. }
  29. dispatch(setDocumentUrl(url));
  30. }
  31. );
  32. break;
  33. }
  34. case TOGGLE_DOCUMENT_EDITING: {
  35. if (typeof APP !== 'undefined') {
  36. APP.UI.emitEvent(UIEvents.ETHERPAD_CLICKED);
  37. }
  38. break;
  39. }
  40. }
  41. return next(action);
  42. });
  43. /**
  44. * Set up state change listener to perform maintenance tasks when the conference
  45. * is left or failed, e.g. Clear messages or close the chat modal if it's left
  46. * open.
  47. */
  48. StateListenerRegistry.register(
  49. state => getCurrentConference(state),
  50. (conference, { dispatch }, previousConference) => {
  51. if (previousConference) {
  52. dispatch(setDocumentUrl(undefined));
  53. }
  54. });