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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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_PREJOIN_DEVICE_ERRORS,
  11. SET_PREJOIN_PAGE_VISIBILITY,
  12. SET_SKIP_PREJOIN_RELOAD
  13. } from './actionTypes';
  14. const DEFAULT_STATE = {
  15. country: '',
  16. deviceStatusText: 'prejoin.configuringDevices',
  17. deviceStatusType: 'pending',
  18. dialOutCountry: {
  19. name: 'United States',
  20. dialCode: '1',
  21. code: 'us'
  22. },
  23. dialOutNumber: '',
  24. dialOutStatus: 'prejoin.dialing',
  25. name: '',
  26. rawError: '',
  27. showPrejoin: true,
  28. skipPrejoinOnReload: false,
  29. showJoinByPhoneDialog: false
  30. };
  31. export interface IPrejoinState {
  32. country: string;
  33. deviceStatusText: string;
  34. deviceStatusType: string;
  35. dialOutCountry: {
  36. code: string;
  37. dialCode: string;
  38. name: string;
  39. };
  40. dialOutNumber: string;
  41. dialOutStatus: string;
  42. joiningInProgress?: boolean;
  43. name: string;
  44. rawError: string;
  45. showJoinByPhoneDialog: boolean;
  46. showPrejoin: boolean;
  47. skipPrejoinOnReload: boolean;
  48. }
  49. /**
  50. * Sets up the persistence of the feature {@code prejoin}.
  51. */
  52. PersistenceRegistry.register('features/prejoin', {
  53. skipPrejoinOnReload: true
  54. }, DEFAULT_STATE);
  55. /**
  56. * Listen for actions that mutate the prejoin state.
  57. */
  58. ReducerRegistry.register<IPrejoinState>(
  59. 'features/prejoin', (state = DEFAULT_STATE, action): IPrejoinState => {
  60. switch (action.type) {
  61. case PREJOIN_JOINING_IN_PROGRESS:
  62. return {
  63. ...state,
  64. joiningInProgress: action.value
  65. };
  66. case SET_SKIP_PREJOIN_RELOAD: {
  67. return {
  68. ...state,
  69. skipPrejoinOnReload: action.value
  70. };
  71. }
  72. case SET_PREJOIN_PAGE_VISIBILITY:
  73. return {
  74. ...state,
  75. showPrejoin: action.value
  76. };
  77. case SET_PREJOIN_DEVICE_ERRORS: {
  78. const status = getStatusFromErrors(action.value);
  79. return {
  80. ...state,
  81. ...status
  82. };
  83. }
  84. case SET_DEVICE_STATUS: {
  85. const { deviceStatusType, deviceStatusText } = action.value;
  86. return {
  87. ...state,
  88. deviceStatusText,
  89. deviceStatusType
  90. };
  91. }
  92. case SET_DIALOUT_NUMBER: {
  93. return {
  94. ...state,
  95. dialOutNumber: action.value
  96. };
  97. }
  98. case SET_DIALOUT_COUNTRY: {
  99. return {
  100. ...state,
  101. dialOutCountry: action.value
  102. };
  103. }
  104. case SET_DIALOUT_STATUS: {
  105. return {
  106. ...state,
  107. dialOutStatus: action.value
  108. };
  109. }
  110. case SET_JOIN_BY_PHONE_DIALOG_VISIBLITY: {
  111. return {
  112. ...state,
  113. showJoinByPhoneDialog: action.value
  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. audioAndVideoError?: { message: string; };
  129. audioOnlyError?: { message: string; };
  130. videoOnlyError?: { message: string; }; }
  131. ) {
  132. const { audioOnlyError, videoOnlyError, audioAndVideoError } = errors;
  133. if (audioAndVideoError) {
  134. return {
  135. deviceStatusType: 'warning',
  136. deviceStatusText: 'prejoin.audioAndVideoError',
  137. rawError: audioAndVideoError.message
  138. };
  139. }
  140. if (audioOnlyError) {
  141. return {
  142. deviceStatusType: 'warning',
  143. deviceStatusText: 'prejoin.audioOnlyError',
  144. rawError: audioOnlyError.message
  145. };
  146. }
  147. if (videoOnlyError) {
  148. return {
  149. deviceStatusType: 'warning',
  150. deviceStatusText: 'prejoin.videoOnlyError',
  151. rawError: videoOnlyError.message
  152. };
  153. }
  154. return {
  155. deviceStatusType: 'ok',
  156. deviceStatusText: 'prejoin.lookGood',
  157. rawError: ''
  158. };
  159. }