jiti-meet/react/features/base/known-domains/middleware.ts

56 lines
1.4 KiB
TypeScript
Raw Normal View History

import { getDefaultURL } from '../../app/functions';
import { IStore } from '../../app/types';
import { APP_WILL_MOUNT } from '../app/actionTypes';
import { SET_ROOM } from '../conference/actionTypes';
import MiddlewareRegistry from '../redux/MiddlewareRegistry';
import { parseURIString } from '../util/uri';
2018-05-11 15:27:37 +00:00
import { addKnownDomains } from './actions';
MiddlewareRegistry.register(store => next => action => {
const result = next(action);
switch (action.type) {
case APP_WILL_MOUNT:
2018-05-14 15:55:40 +00:00
_appWillMount(store);
2018-05-11 15:27:37 +00:00
break;
case SET_ROOM:
2018-05-14 15:55:40 +00:00
_setRoom(store);
2018-05-11 15:27:37 +00:00
break;
}
return result;
});
/**
2018-05-14 15:55:40 +00:00
* Adds the domain of the app's {@code defaultURL} to the list of domains known
* to the feature base/known-domains.
2018-05-11 15:27:37 +00:00
*
* @param {Object} store - The redux store.
* @private
* @returns {Promise}
*/
function _appWillMount({ dispatch, getState }: IStore) {
const defaultURL = parseURIString(getDefaultURL(getState));
2018-05-14 15:55:40 +00:00
dispatch(addKnownDomains(defaultURL?.host));
2018-05-11 15:27:37 +00:00
}
/**
2018-05-14 15:55:40 +00:00
* Adds the domain of {@code locationURL} to the list of domains known to the
* feature base/known-domains.
2018-05-11 15:27:37 +00:00
*
* @param {Object} store - The redux store.
* @private
* @returns {Promise}
*/
function _setRoom({ dispatch, getState }: IStore) {
2018-05-11 15:27:37 +00:00
const { locationURL } = getState()['features/base/connection'];
2018-05-14 15:55:40 +00:00
let host;
2018-05-11 15:27:37 +00:00
locationURL
2018-05-14 15:55:40 +00:00
&& (host = locationURL.host)
&& dispatch(addKnownDomains(host));
2018-05-11 15:27:37 +00:00
}