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.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import ReducerRegistry from '../base/redux/ReducerRegistry';
  2. import {
  3. ADD_PENDING_INVITE_REQUEST,
  4. REMOVE_PENDING_INVITE_REQUESTS,
  5. SET_CALLEE_INFO_VISIBLE,
  6. UPDATE_DIAL_IN_NUMBERS_FAILED,
  7. UPDATE_DIAL_IN_NUMBERS_SUCCESS
  8. } from './actionTypes';
  9. import logger from './logger';
  10. const DEFAULT_STATE = {
  11. /**
  12. * The indicator which determines whether (the) {@code CalleeInfo} is
  13. * visible.
  14. *
  15. * @type {boolean|undefined}
  16. */
  17. calleeInfoVisible: false,
  18. numbersEnabled: true,
  19. numbersFetched: false,
  20. pendingInviteRequests: []
  21. };
  22. export interface IInviteState {
  23. calleeInfoVisible?: boolean;
  24. conferenceID?: string | number;
  25. error?: Error;
  26. initialCalleeInfo?: Object;
  27. numbers?: string;
  28. numbersEnabled: boolean;
  29. numbersFetched: boolean;
  30. pendingInviteRequests: Array<{
  31. callback: Function;
  32. invitees: Array<Object>;
  33. }>;
  34. sipUri?: string;
  35. }
  36. ReducerRegistry.register<IInviteState>('features/invite', (state = DEFAULT_STATE, action): IInviteState => {
  37. switch (action.type) {
  38. case ADD_PENDING_INVITE_REQUEST:
  39. return {
  40. ...state,
  41. pendingInviteRequests: [
  42. ...state.pendingInviteRequests,
  43. action.request
  44. ]
  45. };
  46. case REMOVE_PENDING_INVITE_REQUESTS:
  47. return {
  48. ...state,
  49. pendingInviteRequests: []
  50. };
  51. case SET_CALLEE_INFO_VISIBLE:
  52. return {
  53. ...state,
  54. calleeInfoVisible: action.calleeInfoVisible,
  55. initialCalleeInfo: action.initialCalleeInfo
  56. };
  57. case UPDATE_DIAL_IN_NUMBERS_FAILED:
  58. return {
  59. ...state,
  60. error: action.error
  61. };
  62. case UPDATE_DIAL_IN_NUMBERS_SUCCESS: {
  63. if (Array.isArray(action.dialInNumbers)) {
  64. return {
  65. ...state,
  66. conferenceID: action.conferenceID,
  67. numbers: action.dialInNumbers,
  68. sipUri: action.sipUri,
  69. numbersEnabled: true,
  70. numbersFetched: true
  71. };
  72. }
  73. // this is the old format which is deprecated
  74. logger.warn('Using deprecated API for retrieving phone numbers');
  75. const { numbersEnabled } = action.dialInNumbers;
  76. return {
  77. ...state,
  78. conferenceID: action.conferenceID,
  79. numbers: action.dialInNumbers,
  80. numbersEnabled,
  81. numbersFetched: true
  82. };
  83. }
  84. }
  85. return state;
  86. });