您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

reducer.js 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. return {
  63. ...state,
  64. deviceStatusText: action.text,
  65. deviceStatusType: action.type
  66. };
  67. }
  68. case SET_DIALOUT_NUMBER: {
  69. return {
  70. ...state,
  71. dialOutNumber: action.value
  72. };
  73. }
  74. case SET_DIALOUT_COUNTRY: {
  75. return {
  76. ...state,
  77. dialOutCountry: action.value
  78. };
  79. }
  80. case SET_DIALOUT_STATUS: {
  81. return {
  82. ...state,
  83. dialOutStatus: action.value
  84. };
  85. }
  86. case SET_JOIN_BY_PHONE_DIALOG_VISIBLITY: {
  87. return {
  88. ...state,
  89. showJoinByPhoneDialog: action.value
  90. };
  91. }
  92. case SET_PREJOIN_DISPLAY_NAME_REQUIRED: {
  93. return {
  94. ...state,
  95. isDisplayNameRequired: true
  96. };
  97. }
  98. default:
  99. return state;
  100. }
  101. },
  102. );
  103. /**
  104. * Returns a suitable error object based on the track errors.
  105. *
  106. * @param {Object} errors - The errors got while creating local tracks.
  107. * @returns {Object}
  108. */
  109. function getStatusFromErrors(errors) {
  110. const { audioOnlyError, videoOnlyError, audioAndVideoError } = errors;
  111. if (audioAndVideoError) {
  112. if (audioOnlyError) {
  113. if (videoOnlyError) {
  114. return {
  115. deviceStatusType: 'warning',
  116. deviceStatusText: 'prejoin.audioAndVideoError',
  117. rawError: audioAndVideoError.message
  118. };
  119. }
  120. return {
  121. deviceStatusType: 'warning',
  122. deviceStatusText: 'prejoin.audioOnlyError',
  123. rawError: audioOnlyError.message
  124. };
  125. }
  126. return {
  127. deviceStatusType: 'warning',
  128. deviceStatusText: 'prejoin.videoOnlyError',
  129. rawError: audioAndVideoError.message
  130. };
  131. }
  132. return {
  133. deviceStatusType: 'ok',
  134. deviceStatusText: 'prejoin.lookGood',
  135. rawError: ''
  136. };
  137. }