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

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