You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reducer.ts 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import ReducerRegistry from '../base/redux/ReducerRegistry';
  2. import { assign } from '../base/redux/functions';
  3. import {
  4. CANCEL_LOGIN,
  5. STOP_WAIT_FOR_OWNER,
  6. UPGRADE_ROLE_FINISHED,
  7. UPGRADE_ROLE_STARTED,
  8. WAIT_FOR_OWNER
  9. } from './actionTypes';
  10. export interface IAuthenticationState {
  11. error?: Object | undefined;
  12. progress?: number | undefined;
  13. thenableWithCancel?: {
  14. cancel: Function;
  15. };
  16. waitForOwnerTimeoutID?: number;
  17. }
  18. /**
  19. * Listens for actions which change the state of the authentication feature.
  20. *
  21. * @param {Object} state - The Redux state of the authentication feature.
  22. * @param {Object} action - Action object.
  23. * @param {string} action.type - Type of action.
  24. * @returns {Object}
  25. */
  26. ReducerRegistry.register<IAuthenticationState>('features/authentication',
  27. (state = {}, action): IAuthenticationState => {
  28. switch (action.type) {
  29. case CANCEL_LOGIN:
  30. return assign(state, {
  31. error: undefined,
  32. progress: undefined,
  33. thenableWithCancel: undefined
  34. });
  35. case STOP_WAIT_FOR_OWNER:
  36. return assign(state, {
  37. error: undefined,
  38. waitForOwnerTimeoutID: undefined
  39. });
  40. case UPGRADE_ROLE_FINISHED: {
  41. let { thenableWithCancel } = action;
  42. if (state.thenableWithCancel === thenableWithCancel) {
  43. const { error, progress } = action;
  44. // An error interrupts the process of authenticating and upgrading
  45. // the role of the local participant/user i.e. the process is no
  46. // more. Obviously, the process seizes to exist also when it does
  47. // its whole job.
  48. if (error || progress === 1) {
  49. thenableWithCancel = undefined;
  50. }
  51. return assign(state, {
  52. error,
  53. progress: progress || undefined,
  54. thenableWithCancel
  55. });
  56. }
  57. break;
  58. }
  59. case UPGRADE_ROLE_STARTED:
  60. return assign(state, {
  61. error: undefined,
  62. progress: undefined,
  63. thenableWithCancel: action.thenableWithCancel
  64. });
  65. case WAIT_FOR_OWNER:
  66. return assign(state, {
  67. waitForOwnerTimeoutID: action.waitForOwnerTimeoutID
  68. });
  69. }
  70. return state;
  71. });