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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import { ReducerRegistry } from '../base/redux';
  2. import {
  3. ADD_PREJOIN_AUDIO_TRACK,
  4. ADD_PREJOIN_CONTENT_SHARING_TRACK,
  5. ADD_PREJOIN_VIDEO_TRACK,
  6. SET_DEVICE_STATUS,
  7. SET_JOIN_BY_PHONE_DIALOG_VISIBLITY,
  8. SET_PREJOIN_AUDIO_DISABLED,
  9. SET_PREJOIN_AUDIO_MUTED,
  10. SET_PREJOIN_DEVICE_ERRORS,
  11. SET_PREJOIN_NAME,
  12. SET_PREJOIN_PAGE_VISIBILITY,
  13. SET_PREJOIN_VIDEO_DISABLED,
  14. SET_PREJOIN_VIDEO_MUTED
  15. } from './actionTypes';
  16. const DEFAULT_STATE = {
  17. audioDisabled: false,
  18. audioMuted: false,
  19. videoMuted: false,
  20. videoDisabled: false,
  21. deviceStatusText: 'prejoin.configuringDevices',
  22. deviceStatusType: 'ok',
  23. showPrejoin: true,
  24. showJoinByPhoneDialog: false,
  25. videoTrack: null,
  26. audioTrack: null,
  27. contentSharingTrack: null,
  28. rawError: '',
  29. name: ''
  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 ADD_PREJOIN_AUDIO_TRACK: {
  38. return {
  39. ...state,
  40. audioTrack: action.value
  41. };
  42. }
  43. case ADD_PREJOIN_CONTENT_SHARING_TRACK: {
  44. return {
  45. ...state,
  46. contentSharingTrack: action.value
  47. };
  48. }
  49. case ADD_PREJOIN_VIDEO_TRACK: {
  50. return {
  51. ...state,
  52. videoTrack: action.value
  53. };
  54. }
  55. case SET_PREJOIN_NAME: {
  56. return {
  57. ...state,
  58. name: action.value
  59. };
  60. }
  61. case SET_PREJOIN_PAGE_VISIBILITY:
  62. return {
  63. ...state,
  64. showPrejoin: action.value
  65. };
  66. case SET_PREJOIN_VIDEO_DISABLED: {
  67. return {
  68. ...state,
  69. videoDisabled: action.value
  70. };
  71. }
  72. case SET_PREJOIN_VIDEO_MUTED:
  73. return {
  74. ...state,
  75. videoMuted: action.value
  76. };
  77. case SET_PREJOIN_AUDIO_MUTED:
  78. return {
  79. ...state,
  80. audioMuted: action.value
  81. };
  82. case SET_PREJOIN_DEVICE_ERRORS: {
  83. const status = getStatusFromErrors(action.value);
  84. return {
  85. ...state,
  86. ...status
  87. };
  88. }
  89. case SET_DEVICE_STATUS: {
  90. return {
  91. ...state,
  92. deviceStatusText: action.text,
  93. deviceStatusType: action.type
  94. };
  95. }
  96. case SET_PREJOIN_AUDIO_DISABLED: {
  97. return {
  98. ...state,
  99. audioDisabled: true
  100. };
  101. }
  102. case SET_JOIN_BY_PHONE_DIALOG_VISIBLITY: {
  103. return {
  104. ...state,
  105. showJoinByPhoneDialog: action.value
  106. };
  107. }
  108. default:
  109. return state;
  110. }
  111. },
  112. );
  113. /**
  114. * Returns a suitable error object based on the track errors.
  115. *
  116. * @param {Object} errors - The errors got while creating local tracks.
  117. * @returns {Object}
  118. */
  119. function getStatusFromErrors(errors) {
  120. const { audioOnlyError, videoOnlyError, audioAndVideoError } = errors;
  121. if (audioAndVideoError) {
  122. if (audioOnlyError) {
  123. if (videoOnlyError) {
  124. return {
  125. deviceStatusType: 'warning',
  126. deviceStatusText: 'prejoin.audioAndVideoError',
  127. rawError: audioAndVideoError.message
  128. };
  129. }
  130. return {
  131. deviceStatusType: 'warning',
  132. deviceStatusText: 'prejoin.audioOnlyError',
  133. rawError: audioOnlyError.message
  134. };
  135. }
  136. return {
  137. deviceStatusType: 'warning',
  138. deviceStatusText: 'prejoin.videoOnlyError',
  139. rawError: audioAndVideoError.message
  140. };
  141. }
  142. return {
  143. deviceStatusType: 'ok',
  144. deviceStatusText: 'prejoin.lookGood',
  145. rawError: ''
  146. };
  147. }