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.ts 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import PersistenceRegistry from '../base/redux/PersistenceRegistry';
  2. import ReducerRegistry from '../base/redux/ReducerRegistry';
  3. import {
  4. PREJOIN_JOINING_IN_PROGRESS,
  5. SET_DEVICE_STATUS,
  6. SET_DIALOUT_COUNTRY,
  7. SET_DIALOUT_NUMBER,
  8. SET_DIALOUT_STATUS,
  9. SET_JOIN_BY_PHONE_DIALOG_VISIBLITY,
  10. SET_PRECALL_TEST_RESULTS,
  11. SET_PREJOIN_DEVICE_ERRORS,
  12. SET_PREJOIN_DISPLAY_NAME_REQUIRED,
  13. SET_PREJOIN_PAGE_VISIBILITY,
  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. };
  34. export interface IPrejoinState {
  35. country: string;
  36. deviceStatusText: string;
  37. deviceStatusType: string;
  38. dialOutCountry: {
  39. code: string;
  40. dialCode: string;
  41. name: string;
  42. };
  43. dialOutNumber: string;
  44. dialOutStatus: string;
  45. isDisplayNameRequired: boolean;
  46. joiningInProgress?: boolean;
  47. name: string;
  48. precallTestResults?: {
  49. fractionalLoss: number;
  50. mediaConnectivity: boolean;
  51. throughput: number;
  52. };
  53. rawError: string;
  54. showJoinByPhoneDialog: boolean;
  55. showPrejoin: boolean;
  56. skipPrejoinOnReload: boolean;
  57. }
  58. /**
  59. * Sets up the persistence of the feature {@code prejoin}.
  60. */
  61. PersistenceRegistry.register('features/prejoin', {
  62. skipPrejoinOnReload: true
  63. }, DEFAULT_STATE);
  64. /**
  65. * Listen for actions that mutate the prejoin state.
  66. */
  67. ReducerRegistry.register<IPrejoinState>(
  68. 'features/prejoin', (state = DEFAULT_STATE, action): IPrejoinState => {
  69. switch (action.type) {
  70. case PREJOIN_JOINING_IN_PROGRESS:
  71. return {
  72. ...state,
  73. joiningInProgress: action.value
  74. };
  75. case SET_SKIP_PREJOIN_RELOAD: {
  76. return {
  77. ...state,
  78. skipPrejoinOnReload: action.value
  79. };
  80. }
  81. case SET_PRECALL_TEST_RESULTS:
  82. return {
  83. ...state,
  84. precallTestResults: action.value
  85. };
  86. case SET_PREJOIN_PAGE_VISIBILITY:
  87. return {
  88. ...state,
  89. showPrejoin: action.value
  90. };
  91. case SET_PREJOIN_DEVICE_ERRORS: {
  92. const status = getStatusFromErrors(action.value);
  93. return {
  94. ...state,
  95. ...status
  96. };
  97. }
  98. case SET_DEVICE_STATUS: {
  99. const { deviceStatusType, deviceStatusText } = action.value;
  100. return {
  101. ...state,
  102. deviceStatusText,
  103. deviceStatusType
  104. };
  105. }
  106. case SET_DIALOUT_NUMBER: {
  107. return {
  108. ...state,
  109. dialOutNumber: action.value
  110. };
  111. }
  112. case SET_DIALOUT_COUNTRY: {
  113. return {
  114. ...state,
  115. dialOutCountry: action.value
  116. };
  117. }
  118. case SET_DIALOUT_STATUS: {
  119. return {
  120. ...state,
  121. dialOutStatus: action.value
  122. };
  123. }
  124. case SET_JOIN_BY_PHONE_DIALOG_VISIBLITY: {
  125. return {
  126. ...state,
  127. showJoinByPhoneDialog: action.value
  128. };
  129. }
  130. case SET_PREJOIN_DISPLAY_NAME_REQUIRED: {
  131. return {
  132. ...state,
  133. isDisplayNameRequired: true
  134. };
  135. }
  136. default:
  137. return state;
  138. }
  139. }
  140. );
  141. /**
  142. * Returns a suitable error object based on the track errors.
  143. *
  144. * @param {Object} errors - The errors got while creating local tracks.
  145. * @returns {Object}
  146. */
  147. function getStatusFromErrors(errors: {
  148. audioAndVideoError?: { message: string; };
  149. audioOnlyError?: { message: string; };
  150. videoOnlyError?: { message: string; }; }
  151. ) {
  152. const { audioOnlyError, videoOnlyError, audioAndVideoError } = errors;
  153. if (audioAndVideoError) {
  154. return {
  155. deviceStatusType: 'warning',
  156. deviceStatusText: 'prejoin.audioAndVideoError',
  157. rawError: audioAndVideoError.message
  158. };
  159. }
  160. if (audioOnlyError) {
  161. return {
  162. deviceStatusType: 'warning',
  163. deviceStatusText: 'prejoin.audioOnlyError',
  164. rawError: audioOnlyError.message
  165. };
  166. }
  167. if (videoOnlyError) {
  168. return {
  169. deviceStatusType: 'warning',
  170. deviceStatusText: 'prejoin.videoOnlyError',
  171. rawError: videoOnlyError.message
  172. };
  173. }
  174. return {
  175. deviceStatusType: 'ok',
  176. deviceStatusText: 'prejoin.lookGood',
  177. rawError: ''
  178. };
  179. }