2022-10-13 08:26:28 +00:00
|
|
|
// @ts-expect-error
|
2020-05-20 10:57:03 +00:00
|
|
|
import UIEvents from '../../../service/UI/UIEvents';
|
2022-04-06 02:13:39 +00:00
|
|
|
import { CONFERENCE_JOIN_IN_PROGRESS } from '../base/conference/actionTypes';
|
2022-10-13 08:26:28 +00:00
|
|
|
import { getCurrentConference } from '../base/conference/functions';
|
|
|
|
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
|
|
|
|
import StateListenerRegistry from '../base/redux/StateListenerRegistry';
|
2018-03-07 00:28:19 +00:00
|
|
|
|
|
|
|
import { TOGGLE_DOCUMENT_EDITING } from './actionTypes';
|
2021-12-01 13:04:13 +00:00
|
|
|
import { setDocumentUrl } from './actions';
|
2018-03-07 00:28:19 +00:00
|
|
|
|
2019-10-04 15:10:19 +00:00
|
|
|
const ETHERPAD_COMMAND = 'etherpad';
|
|
|
|
|
2018-03-07 00:28:19 +00:00
|
|
|
/**
|
|
|
|
* Middleware that captures actions related to collaborative document editing
|
|
|
|
* and notifies components not hooked into redux.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
// eslint-disable-next-line no-unused-vars
|
2019-10-04 15:10:19 +00:00
|
|
|
MiddlewareRegistry.register(({ dispatch, getState }) => next => action => {
|
2018-03-07 00:28:19 +00:00
|
|
|
switch (action.type) {
|
2022-04-06 02:13:39 +00:00
|
|
|
case CONFERENCE_JOIN_IN_PROGRESS: {
|
|
|
|
const { conference } = action;
|
|
|
|
|
|
|
|
conference.addCommandListener(ETHERPAD_COMMAND,
|
2022-10-13 08:26:28 +00:00
|
|
|
({ value }: { value: string; }) => {
|
2022-04-06 02:13:39 +00:00
|
|
|
let url;
|
|
|
|
const { etherpad_base: etherpadBase } = getState()['features/base/config'];
|
|
|
|
|
|
|
|
if (etherpadBase) {
|
|
|
|
url = new URL(value, etherpadBase).toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(setDocumentUrl(url));
|
|
|
|
}
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
2019-10-04 15:10:19 +00:00
|
|
|
case TOGGLE_DOCUMENT_EDITING: {
|
2021-12-01 13:04:13 +00:00
|
|
|
if (typeof APP !== 'undefined') {
|
2019-10-04 15:10:19 +00:00
|
|
|
APP.UI.emitEvent(UIEvents.ETHERPAD_CLICKED);
|
|
|
|
}
|
2018-03-07 00:28:19 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-10-04 15:10:19 +00:00
|
|
|
}
|
2018-03-07 00:28:19 +00:00
|
|
|
|
|
|
|
return next(action);
|
|
|
|
});
|
2019-10-04 15:10:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set up state change listener to perform maintenance tasks when the conference
|
2021-11-04 21:10:43 +00:00
|
|
|
* is left or failed, e.g. Clear messages or close the chat modal if it's left
|
2019-10-04 15:10:19 +00:00
|
|
|
* open.
|
|
|
|
*/
|
|
|
|
StateListenerRegistry.register(
|
|
|
|
state => getCurrentConference(state),
|
2022-04-06 02:13:39 +00:00
|
|
|
(conference, { dispatch }, previousConference) => {
|
2019-10-04 15:10:19 +00:00
|
|
|
if (previousConference) {
|
|
|
|
dispatch(setDocumentUrl(undefined));
|
|
|
|
}
|
|
|
|
});
|