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.4KB

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