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

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