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-02-27 20:21:28 +00:00
|
|
|
_updateConferenceDuration(store);
|
2018-01-17 11:19:10 +00:00
|
|
|
break;
|
2017-12-13 10:35:42 +00:00
|
|
|
|
|
|
|
case SET_ROOM:
|
2018-02-27 20:21:28 +00:00
|
|
|
_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-18 21:28:25 +00:00
|
|
|
*
|
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.
|
2018-01-18 21:28:25 +00:00
|
|
|
* @private
|
2018-01-17 11:19:10 +00:00
|
|
|
* @returns {void}
|
2018-01-18 21:28:25 +00:00
|
|
|
*/
|
2018-02-27 20:21:28 +00:00
|
|
|
function _maybeStoreCurrentConference({ dispatch, getState }, { room }) {
|
2017-12-13 10:35:42 +00:00
|
|
|
if (room) {
|
2018-02-27 20:21:28 +00:00
|
|
|
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-18 21:28:25 +00:00
|
|
|
*
|
2018-01-17 11:19:10 +00:00
|
|
|
* @param {Store} store - The redux store.
|
2018-01-18 21:28:25 +00:00
|
|
|
* @private
|
2018-01-17 11:19:10 +00:00
|
|
|
* @returns {void}
|
2018-01-18 21:28:25 +00:00
|
|
|
*/
|
2018-02-27 20:21:28 +00:00
|
|
|
function _updateConferenceDuration({ dispatch, getState }) {
|
|
|
|
const { locationURL } = getState()['features/base/connection'];
|
2017-12-13 10:35:42 +00:00
|
|
|
|
2018-02-27 20:21:28 +00:00
|
|
|
dispatch(updateConferenceDuration(locationURL));
|
2017-12-13 10:35:42 +00:00
|
|
|
}
|