jiti-meet/react/features/authentication/reducer.ts

80 lines
2.2 KiB
TypeScript
Raw Normal View History

import ReducerRegistry from '../base/redux/ReducerRegistry';
import { assign } from '../base/redux/functions';
2017-09-08 13:36:42 +00:00
import {
CANCEL_LOGIN,
STOP_WAIT_FOR_OWNER,
2017-09-18 07:09:43 +00:00
UPGRADE_ROLE_FINISHED,
UPGRADE_ROLE_STARTED,
2017-09-08 13:36:42 +00:00
WAIT_FOR_OWNER
} from './actionTypes';
export interface IAuthenticationState {
error?: Object|undefined;
progress?: number|undefined;
thenableWithCancel?: Object|undefined;
waitForOwnerTimeoutID?: number;
}
/**
* Listens for actions which change the state of the authentication feature.
*
* @param {Object} state - The Redux state of the authentication feature.
* @param {Object} action - Action object.
* @param {string} action.type - Type of action.
* @returns {Object}
*/
ReducerRegistry.register('features/authentication', (state: IAuthenticationState = {}, action: any) => {
2017-09-08 13:36:42 +00:00
switch (action.type) {
2017-09-18 07:09:43 +00:00
case CANCEL_LOGIN:
2017-09-08 13:36:42 +00:00
return assign(state, {
2017-09-24 23:41:20 +00:00
error: undefined,
progress: undefined,
thenableWithCancel: undefined
2017-09-08 13:36:42 +00:00
});
2017-09-18 07:09:43 +00:00
case STOP_WAIT_FOR_OWNER:
2017-09-08 13:36:42 +00:00
return assign(state, {
2017-09-24 23:41:20 +00:00
error: undefined,
2017-09-18 07:09:43 +00:00
waitForOwnerTimeoutID: undefined
2017-09-08 13:36:42 +00:00
});
2017-09-18 07:09:43 +00:00
2017-09-24 23:41:20 +00:00
case UPGRADE_ROLE_FINISHED: {
let { thenableWithCancel } = action;
if (state.thenableWithCancel === thenableWithCancel) {
const { error, progress } = action;
2017-09-24 23:41:20 +00:00
// An error interrupts the process of authenticating and upgrading
// the role of the local participant/user i.e. the process is no
// more. Obviously, the process seizes to exist also when it does
// its whole job.
if (error || progress === 1) {
thenableWithCancel = undefined;
}
return assign(state, {
error,
progress: progress || undefined,
thenableWithCancel
});
}
break;
}
case UPGRADE_ROLE_STARTED:
return assign(state, {
2017-09-24 23:41:20 +00:00
error: undefined,
progress: undefined,
thenableWithCancel: action.thenableWithCancel
2017-09-08 13:36:42 +00:00
});
2017-09-18 07:09:43 +00:00
case WAIT_FOR_OWNER:
2017-09-08 13:36:42 +00:00
return assign(state, {
2017-09-18 07:09:43 +00:00
waitForOwnerTimeoutID: action.waitForOwnerTimeoutID
2017-09-08 13:36:42 +00:00
});
}
return state;
});