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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. import { 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_PREJOIN_DEVICE_ERRORS,
  9. SET_PREJOIN_DISPLAY_NAME_REQUIRED,
  10. SET_PREJOIN_PAGE_VISIBILITY,
  11. SET_SKIP_PREJOIN
  12. } from './actionTypes';
  13. const DEFAULT_STATE = {
  14. country: '',
  15. deviceStatusText: 'prejoin.configuringDevices',
  16. deviceStatusType: 'ok',
  17. dialOutCountry: {
  18. name: 'United States',
  19. dialCode: '1',
  20. code: 'us'
  21. },
  22. dialOutNumber: '',
  23. dialOutStatus: 'prejoin.dialing',
  24. isDisplayNameRequired: false,
  25. name: '',
  26. rawError: '',
  27. showPrejoin: true,
  28. showJoinByPhoneDialog: false,
  29. userSelectedSkipPrejoin: false
  30. };
  31. /**
  32. * Listen for actions that mutate the prejoin state
  33. */
  34. ReducerRegistry.register(
  35. 'features/prejoin', (state = DEFAULT_STATE, action) => {
  36. switch (action.type) {
  37. case SET_SKIP_PREJOIN: {
  38. return {
  39. ...state,
  40. userSelectedSkipPrejoin: action.value
  41. };
  42. }
  43. case SET_PREJOIN_PAGE_VISIBILITY:
  44. return {
  45. ...state,
  46. showPrejoin: action.value
  47. };
  48. case SET_PREJOIN_DEVICE_ERRORS: {
  49. const status = getStatusFromErrors(action.value);
  50. return {
  51. ...state,
  52. ...status
  53. };
  54. }
  55. case SET_DEVICE_STATUS: {
  56. return {
  57. ...state,
  58. deviceStatusText: action.text,
  59. deviceStatusType: action.type
  60. };
  61. }
  62. case SET_DIALOUT_NUMBER: {
  63. return {
  64. ...state,
  65. dialOutNumber: action.value
  66. };
  67. }
  68. case SET_DIALOUT_COUNTRY: {
  69. return {
  70. ...state,
  71. dialOutCountry: action.value
  72. };
  73. }
  74. case SET_DIALOUT_STATUS: {
  75. return {
  76. ...state,
  77. dialOutStatus: action.value
  78. };
  79. }
  80. case SET_JOIN_BY_PHONE_DIALOG_VISIBLITY: {
  81. return {
  82. ...state,
  83. showJoinByPhoneDialog: action.value
  84. };
  85. }
  86. case SET_PREJOIN_DISPLAY_NAME_REQUIRED: {
  87. return {
  88. ...state,
  89. isDisplayNameRequired: true
  90. };
  91. }
  92. default:
  93. return state;
  94. }
  95. },
  96. );
  97. /**
  98. * Returns a suitable error object based on the track errors.
  99. *
  100. * @param {Object} errors - The errors got while creating local tracks.
  101. * @returns {Object}
  102. */
  103. function getStatusFromErrors(errors) {
  104. const { audioOnlyError, videoOnlyError, audioAndVideoError } = errors;
  105. if (audioAndVideoError) {
  106. if (audioOnlyError) {
  107. if (videoOnlyError) {
  108. return {
  109. deviceStatusType: 'warning',
  110. deviceStatusText: 'prejoin.audioAndVideoError',
  111. rawError: audioAndVideoError.message
  112. };
  113. }
  114. return {
  115. deviceStatusType: 'warning',
  116. deviceStatusText: 'prejoin.audioOnlyError',
  117. rawError: audioOnlyError.message
  118. };
  119. }
  120. return {
  121. deviceStatusType: 'warning',
  122. deviceStatusText: 'prejoin.videoOnlyError',
  123. rawError: audioAndVideoError.message
  124. };
  125. }
  126. return {
  127. deviceStatusType: 'ok',
  128. deviceStatusText: 'prejoin.lookGood',
  129. rawError: ''
  130. };
  131. }