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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. import { ReducerRegistry } from '../base/redux';
  2. import {
  3. SET_DEVICE_STATUS,
  4. SET_DIALOUT_COUNTRY,
  5. SET_DIALOUT_NUMBER,
  6. SET_DIALOUT_STATUS,
  7. SET_JOIN_BY_PHONE_DIALOG_VISIBLITY,
  8. SET_PRECALL_TEST_RESULTS,
  9. SET_PREJOIN_DEVICE_ERRORS,
  10. SET_PREJOIN_DISPLAY_NAME_REQUIRED,
  11. SET_PREJOIN_PAGE_VISIBILITY,
  12. SET_SKIP_PREJOIN
  13. } from './actionTypes';
  14. const DEFAULT_STATE = {
  15. country: '',
  16. deviceStatusText: 'prejoin.configuringDevices',
  17. deviceStatusType: 'ok',
  18. dialOutCountry: {
  19. name: 'United States',
  20. dialCode: '1',
  21. code: 'us'
  22. },
  23. dialOutNumber: '',
  24. dialOutStatus: 'prejoin.dialing',
  25. isDisplayNameRequired: false,
  26. name: '',
  27. rawError: '',
  28. showPrejoin: true,
  29. showJoinByPhoneDialog: false,
  30. userSelectedSkipPrejoin: false
  31. };
  32. /**
  33. * Listen for actions that mutate the prejoin state
  34. */
  35. ReducerRegistry.register(
  36. 'features/prejoin', (state = DEFAULT_STATE, action) => {
  37. switch (action.type) {
  38. case SET_SKIP_PREJOIN: {
  39. return {
  40. ...state,
  41. userSelectedSkipPrejoin: action.value
  42. };
  43. }
  44. case SET_PRECALL_TEST_RESULTS:
  45. return {
  46. ...state,
  47. precallTestResults: action.value
  48. };
  49. case SET_PREJOIN_PAGE_VISIBILITY:
  50. return {
  51. ...state,
  52. showPrejoin: action.value
  53. };
  54. case SET_PREJOIN_DEVICE_ERRORS: {
  55. const status = getStatusFromErrors(action.value);
  56. return {
  57. ...state,
  58. ...status
  59. };
  60. }
  61. case SET_DEVICE_STATUS: {
  62. const { deviceStatusType, deviceStatusText } = action.value;
  63. return {
  64. ...state,
  65. deviceStatusText,
  66. deviceStatusType
  67. };
  68. }
  69. case SET_DIALOUT_NUMBER: {
  70. return {
  71. ...state,
  72. dialOutNumber: action.value
  73. };
  74. }
  75. case SET_DIALOUT_COUNTRY: {
  76. return {
  77. ...state,
  78. dialOutCountry: action.value
  79. };
  80. }
  81. case SET_DIALOUT_STATUS: {
  82. return {
  83. ...state,
  84. dialOutStatus: action.value
  85. };
  86. }
  87. case SET_JOIN_BY_PHONE_DIALOG_VISIBLITY: {
  88. return {
  89. ...state,
  90. showJoinByPhoneDialog: action.value
  91. };
  92. }
  93. case SET_PREJOIN_DISPLAY_NAME_REQUIRED: {
  94. return {
  95. ...state,
  96. isDisplayNameRequired: true
  97. };
  98. }
  99. default:
  100. return state;
  101. }
  102. },
  103. );
  104. /**
  105. * Returns a suitable error object based on the track errors.
  106. *
  107. * @param {Object} errors - The errors got while creating local tracks.
  108. * @returns {Object}
  109. */
  110. function getStatusFromErrors(errors) {
  111. const { audioOnlyError, videoOnlyError, audioAndVideoError } = errors;
  112. if (audioAndVideoError) {
  113. if (audioOnlyError) {
  114. if (videoOnlyError) {
  115. return {
  116. deviceStatusType: 'warning',
  117. deviceStatusText: 'prejoin.audioAndVideoError',
  118. rawError: audioAndVideoError.message
  119. };
  120. }
  121. return {
  122. deviceStatusType: 'warning',
  123. deviceStatusText: 'prejoin.audioOnlyError',
  124. rawError: audioOnlyError.message
  125. };
  126. }
  127. return {
  128. deviceStatusType: 'warning',
  129. deviceStatusText: 'prejoin.videoOnlyError',
  130. rawError: audioAndVideoError.message
  131. };
  132. }
  133. return {
  134. deviceStatusType: 'ok',
  135. deviceStatusText: 'prejoin.lookGood',
  136. rawError: ''
  137. };
  138. }