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

middleware.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // @flow
  2. import UIEvents from '../../../service/UI/UIEvents';
  3. import { getCurrentConference } from '../base/conference';
  4. import { MiddlewareRegistry, StateListenerRegistry } from '../base/redux';
  5. import { TOGGLE_DOCUMENT_EDITING } from './actionTypes';
  6. import { 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. APP.UI.emitEvent(UIEvents.ETHERPAD_CLICKED);
  22. }
  23. break;
  24. }
  25. }
  26. return next(action);
  27. });
  28. /**
  29. * Set up state change listener to perform maintenance tasks when the conference
  30. * is left or failed, e.g. Clear messages or close the chat modal if it's left
  31. * open.
  32. */
  33. StateListenerRegistry.register(
  34. state => getCurrentConference(state),
  35. (conference, { dispatch, getState }, previousConference) => {
  36. if (conference) {
  37. conference.addCommandListener(ETHERPAD_COMMAND,
  38. ({ value }) => {
  39. let url;
  40. const { etherpad_base: etherpadBase } = getState()['features/base/config'];
  41. if (etherpadBase) {
  42. const u = new URL(value, etherpadBase);
  43. url = u.toString();
  44. }
  45. dispatch(setDocumentUrl(url));
  46. }
  47. );
  48. }
  49. if (previousConference) {
  50. dispatch(setDocumentUrl(undefined));
  51. }
  52. });