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

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