2022-12-14 12:23:07 +00:00
|
|
|
import { AnyAction } from 'redux';
|
|
|
|
|
|
|
|
import { IStore } from '../app/types';
|
|
|
|
import { APP_WILL_MOUNT } from '../base/app/actionTypes';
|
|
|
|
import { CONFERENCE_WILL_LEAVE, SET_ROOM } from '../base/conference/actionTypes';
|
|
|
|
import { JITSI_CONFERENCE_URL_KEY } from '../base/conference/constants';
|
|
|
|
import { addKnownDomains } from '../base/known-domains/actions';
|
|
|
|
import MiddlewareRegistry from '../base/redux/MiddlewareRegistry';
|
2022-05-23 11:28:34 +00:00
|
|
|
import { inIframe } from '../base/util/iframeUtils';
|
2022-12-14 12:23:07 +00:00
|
|
|
import { parseURIString } from '../base/util/uri';
|
2017-12-13 10:35:42 +00:00
|
|
|
|
2018-05-14 17:37:48 +00:00
|
|
|
import { _storeCurrentConference, _updateConferenceDuration } from './actions';
|
2018-08-01 20:37:15 +00:00
|
|
|
import { isRecentListEnabled } from './functions';
|
2017-12-20 00:49:36 +00:00
|
|
|
|
2017-12-13 10:35:42 +00:00
|
|
|
/**
|
2017-12-20 00:49:36 +00:00
|
|
|
* Middleware that captures joined rooms so they can be saved into
|
|
|
|
* {@code window.localStorage}.
|
2017-12-13 10:35:42 +00:00
|
|
|
*
|
2017-12-20 00:49:36 +00:00
|
|
|
* @param {Store} store - The redux store.
|
2017-12-13 10:35:42 +00:00
|
|
|
* @returns {Function}
|
|
|
|
*/
|
|
|
|
MiddlewareRegistry.register(store => next => action => {
|
2018-08-01 20:37:15 +00:00
|
|
|
if (isRecentListEnabled()) {
|
2018-08-01 16:41:54 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case APP_WILL_MOUNT:
|
|
|
|
return _appWillMount(store, next, action);
|
2018-05-14 17:37:48 +00:00
|
|
|
|
2018-08-01 16:41:54 +00:00
|
|
|
case CONFERENCE_WILL_LEAVE:
|
|
|
|
return _conferenceWillLeave(store, next, action);
|
2017-12-13 10:35:42 +00:00
|
|
|
|
2018-08-01 16:41:54 +00:00
|
|
|
case SET_ROOM:
|
|
|
|
return _setRoom(store, next, action);
|
|
|
|
}
|
2017-12-13 10:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
2018-05-14 17:37:48 +00:00
|
|
|
* Notifies the feature recent-list that the redux action {@link APP_WILL_MOUNT}
|
|
|
|
* is being dispatched in a specific redux store.
|
2018-01-18 21:28:25 +00:00
|
|
|
*
|
2018-05-14 17:37:48 +00:00
|
|
|
* @param {Store} store - The redux store in which the specified action is being
|
|
|
|
* dispatched.
|
|
|
|
* @param {Dispatch} next - The redux {@code dispatch} function to dispatch the
|
|
|
|
* specified action to the specified store.
|
|
|
|
* @param {Action} action - The redux action {@code APP_WILL_MOUNT} which is
|
|
|
|
* being dispatched in the specified redux store.
|
2018-01-18 21:28:25 +00:00
|
|
|
* @private
|
2018-05-14 17:37:48 +00:00
|
|
|
* @returns {*} The result returned by {@code next(action)}.
|
2018-01-18 21:28:25 +00:00
|
|
|
*/
|
2022-12-14 12:23:07 +00:00
|
|
|
function _appWillMount({ dispatch, getState }: IStore, next: Function, action: AnyAction) {
|
2018-05-14 17:37:48 +00:00
|
|
|
const result = next(action);
|
|
|
|
|
|
|
|
// It's an opportune time to transfer the feature recent-list's knowledge
|
|
|
|
// about "known domains" (which is local to the feature) to the feature
|
|
|
|
// base/known-domains (which is global to the app).
|
|
|
|
//
|
|
|
|
// XXX Since the feature recent-list predates the feature calendar-sync and,
|
|
|
|
// consequently, the feature known-domains, it's possible for the feature
|
|
|
|
// known-list to know of domains which the feature known-domains is yet to
|
|
|
|
// discover.
|
|
|
|
const knownDomains = [];
|
2018-02-27 20:21:28 +00:00
|
|
|
|
2018-05-14 17:37:48 +00:00
|
|
|
for (const { conference } of getState()['features/recent-list']) {
|
|
|
|
const uri = parseURIString(conference);
|
|
|
|
let host;
|
|
|
|
|
|
|
|
uri && (host = uri.host) && knownDomains.push(host);
|
2017-12-13 10:35:42 +00:00
|
|
|
}
|
2018-05-14 17:37:48 +00:00
|
|
|
knownDomains.length && dispatch(addKnownDomains(knownDomains));
|
|
|
|
|
|
|
|
return result;
|
2017-12-13 10:35:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-01-17 11:19:10 +00:00
|
|
|
* Updates the duration of the last conference stored in the list.
|
2018-01-18 21:28:25 +00:00
|
|
|
*
|
2018-01-17 11:19:10 +00:00
|
|
|
* @param {Store} store - The redux store.
|
2018-05-14 17:37:48 +00:00
|
|
|
* @param {Dispatch} next - The redux {@code dispatch} function.
|
|
|
|
* @param {Action} action - The redux action {@link CONFERENCE_WILL_LEAVE}.
|
2018-01-18 21:28:25 +00:00
|
|
|
* @private
|
2018-05-14 17:37:48 +00:00
|
|
|
* @returns {*} The result returned by {@code next(action)}.
|
2018-01-18 21:28:25 +00:00
|
|
|
*/
|
2022-12-14 12:23:07 +00:00
|
|
|
function _conferenceWillLeave({ dispatch, getState }: IStore, next: Function, action: AnyAction) {
|
2020-04-09 13:26:19 +00:00
|
|
|
const { doNotStoreRoom } = getState()['features/base/config'];
|
|
|
|
|
2022-05-23 11:28:34 +00:00
|
|
|
if (!doNotStoreRoom && !inIframe()) {
|
2020-04-09 13:26:19 +00:00
|
|
|
let locationURL;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FIXME:
|
|
|
|
* It is better to use action.conference[JITSI_CONFERENCE_URL_KEY]
|
|
|
|
* in order to make sure we get the url the conference is leaving
|
2021-11-04 21:10:43 +00:00
|
|
|
* from (i.e. The room we are leaving from) because if the order of events
|
2021-03-16 15:59:33 +00:00
|
|
|
* is different, we cannot be guaranteed that the location URL in base
|
2021-11-04 21:10:43 +00:00
|
|
|
* connection is the url we are leaving from... Not the one we are going to
|
2020-04-09 13:26:19 +00:00
|
|
|
* (the latter happens on mobile -- if we use the web implementation);
|
|
|
|
* however, the conference object on web does not have
|
2021-11-04 21:10:43 +00:00
|
|
|
* JITSI_CONFERENCE_URL_KEY so we cannot call it and must use the other way.
|
2020-04-09 13:26:19 +00:00
|
|
|
*/
|
|
|
|
if (typeof APP === 'undefined') {
|
|
|
|
locationURL = action.conference[JITSI_CONFERENCE_URL_KEY];
|
|
|
|
} else {
|
|
|
|
locationURL = getState()['features/base/connection'].locationURL;
|
|
|
|
}
|
|
|
|
dispatch(
|
|
|
|
_updateConferenceDuration(
|
|
|
|
locationURL));
|
2018-08-01 16:41:54 +00:00
|
|
|
}
|
2017-12-13 10:35:42 +00:00
|
|
|
|
2018-05-14 17:37:48 +00:00
|
|
|
return next(action);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if there is a current conference (upon SET_ROOM action), and saves it
|
|
|
|
* if necessary.
|
|
|
|
*
|
|
|
|
* @param {Store} store - The redux store.
|
|
|
|
* @param {Dispatch} next - The redux {@code dispatch} function.
|
|
|
|
* @param {Action} action - The redux action {@link SET_ROOM}.
|
|
|
|
* @private
|
|
|
|
* @returns {*} The result returned by {@code next(action)}.
|
|
|
|
*/
|
2022-12-14 12:23:07 +00:00
|
|
|
function _setRoom({ dispatch, getState }: IStore, next: Function, action: AnyAction) {
|
2020-04-09 13:26:19 +00:00
|
|
|
const { doNotStoreRoom } = getState()['features/base/config'];
|
|
|
|
|
2022-05-23 11:28:34 +00:00
|
|
|
if (!doNotStoreRoom && !inIframe() && action.room) {
|
2018-05-14 17:37:48 +00:00
|
|
|
const { locationURL } = getState()['features/base/connection'];
|
|
|
|
|
|
|
|
if (locationURL) {
|
|
|
|
dispatch(_storeCurrentConference(locationURL));
|
|
|
|
|
|
|
|
// Whatever domain the feature recent-list knows about, the app as a
|
|
|
|
// whole should know about.
|
|
|
|
//
|
|
|
|
// XXX Technically, _storeCurrentConference could be turned into an
|
|
|
|
// asynchronous action creator which dispatches both
|
|
|
|
// _STORE_CURRENT_CONFERENCE and addKnownDomains but...
|
|
|
|
dispatch(addKnownDomains(locationURL.host));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return next(action);
|
2017-12-13 10:35:42 +00:00
|
|
|
}
|