Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

reducer.js 4.3KB

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