jiti-meet/react/features/recent-list/middleware.js

59 lines
1.5 KiB
JavaScript
Raw Normal View History

2017-12-20 00:49:36 +00:00
// @flow
2017-12-13 10:35:42 +00:00
import { CONFERENCE_WILL_LEAVE, SET_ROOM } from '../base/conference';
import { MiddlewareRegistry } from '../base/redux';
2018-01-17 11:19:10 +00:00
import { storeCurrentConference, updateConferenceDuration } from './actions';
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 => {
switch (action.type) {
case CONFERENCE_WILL_LEAVE:
_updateConferenceDuration(store);
2018-01-17 11:19:10 +00:00
break;
2017-12-13 10:35:42 +00:00
case SET_ROOM:
_maybeStoreCurrentConference(store, action);
2018-01-17 11:19:10 +00:00
break;
2017-12-13 10:35:42 +00:00
}
return next(action);
});
/**
2018-01-17 11:19:10 +00:00
* Checks if there is a current conference (upon SET_ROOM action), and saves it
* if necessary.
*
2018-01-17 11:19:10 +00:00
* @param {Store} store - The redux store.
* @param {Dispatch} next - The redux {@code dispatch} function.
* @param {Action} action - The redux action.
* @private
2018-01-17 11:19:10 +00:00
* @returns {void}
*/
function _maybeStoreCurrentConference({ dispatch, getState }, { room }) {
2017-12-13 10:35:42 +00:00
if (room) {
const { locationURL } = getState()['features/base/connection'];
dispatch(storeCurrentConference(locationURL));
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-17 11:19:10 +00:00
* @param {Store} store - The redux store.
* @private
2018-01-17 11:19:10 +00:00
* @returns {void}
*/
function _updateConferenceDuration({ dispatch, getState }) {
const { locationURL } = getState()['features/base/connection'];
2017-12-13 10:35:42 +00:00
dispatch(updateConferenceDuration(locationURL));
2017-12-13 10:35:42 +00:00
}