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

66 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-09-18 07:09:43 +00:00
/* @flow */
import { assign, ReducerRegistry } from '../base/redux';
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';
2017-09-18 07:09:43 +00:00
ReducerRegistry.register('features/authentication', (state = {}, action) => {
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;
});