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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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?: Error;
  27. initialCalleeInfo?: Object;
  28. numbers?: string[];
  29. numbersEnabled: boolean;
  30. numbersFetched: boolean;
  31. pendingInviteRequests: Array<{
  32. callback: Function;
  33. invitees: IInvitee[];
  34. }>;
  35. sipUri?: string;
  36. }
  37. ReducerRegistry.register<IInviteState>('features/invite', (state = DEFAULT_STATE, action): IInviteState => {
  38. switch (action.type) {
  39. case ADD_PENDING_INVITE_REQUEST:
  40. return {
  41. ...state,
  42. pendingInviteRequests: [
  43. ...state.pendingInviteRequests,
  44. action.request
  45. ]
  46. };
  47. case REMOVE_PENDING_INVITE_REQUESTS:
  48. return {
  49. ...state,
  50. pendingInviteRequests: []
  51. };
  52. case SET_CALLEE_INFO_VISIBLE:
  53. return {
  54. ...state,
  55. calleeInfoVisible: action.calleeInfoVisible,
  56. initialCalleeInfo: action.initialCalleeInfo
  57. };
  58. case UPDATE_DIAL_IN_NUMBERS_FAILED:
  59. return {
  60. ...state,
  61. error: action.error
  62. };
  63. case UPDATE_DIAL_IN_NUMBERS_SUCCESS: {
  64. if (Array.isArray(action.dialInNumbers)) {
  65. return {
  66. ...state,
  67. conferenceID: action.conferenceID,
  68. numbers: action.dialInNumbers,
  69. sipUri: action.sipUri,
  70. numbersEnabled: true,
  71. numbersFetched: true
  72. };
  73. }
  74. // this is the old format which is deprecated
  75. logger.warn('Using deprecated API for retrieving phone numbers');
  76. const { numbersEnabled } = action.dialInNumbers;
  77. return {
  78. ...state,
  79. conferenceID: action.conferenceID,
  80. numbers: action.dialInNumbers,
  81. numbersEnabled,
  82. numbersFetched: true
  83. };
  84. }
  85. }
  86. return state;
  87. });