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

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