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

middleware.js 2.0KB

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