選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

reducer.ts 4.6KB

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