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

62 lines
1.6 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:
2018-01-17 11:19:10 +00:00
_updateConferenceDuration(store, next);
break;
2017-12-13 10:35:42 +00:00
case SET_ROOM:
2018-01-17 11:19:10 +00:00
_maybeStoreCurrentConference(store, next, action);
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}
*/
2018-01-17 11:19:10 +00:00
function _maybeStoreCurrentConference(store, next, action) {
const { locationURL } = store.getState()['features/base/connection'];
2017-12-13 10:35:42 +00:00
const { room } = action;
if (room) {
2018-01-17 11:19:10 +00:00
next(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.
* @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}
*/
2018-01-17 11:19:10 +00:00
function _updateConferenceDuration(store, next) {
const { locationURL } = store.getState()['features/base/connection'];
2017-12-13 10:35:42 +00:00
2018-01-17 11:19:10 +00:00
next(updateConferenceDuration(locationURL));
2017-12-13 10:35:42 +00:00
}