您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

AudioSettingsPopup.tsx 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import React, { ReactNode } from 'react';
  2. import { connect } from 'react-redux';
  3. import { makeStyles } from 'tss-react/mui';
  4. import { IReduxState } from '../../../../app/types';
  5. import { areAudioLevelsEnabled } from '../../../../base/config/functions.web';
  6. import {
  7. setAudioInputDeviceAndUpdateSettings,
  8. setAudioOutputDevice as setAudioOutputDeviceAction
  9. } from '../../../../base/devices/actions.web';
  10. import {
  11. getAudioInputDeviceData,
  12. getAudioOutputDeviceData
  13. } from '../../../../base/devices/functions.web';
  14. import Popover from '../../../../base/popover/components/Popover.web';
  15. import { SMALL_MOBILE_WIDTH } from '../../../../base/responsive-ui/constants';
  16. import {
  17. getCurrentMicDeviceId,
  18. getCurrentOutputDeviceId
  19. } from '../../../../base/settings/functions.web';
  20. import { toggleAudioSettings } from '../../../actions';
  21. import { getAudioSettingsVisibility } from '../../../functions.web';
  22. import AudioSettingsContent from './AudioSettingsContent';
  23. interface IProps {
  24. /**
  25. * Component's children (the audio button).
  26. */
  27. children: ReactNode;
  28. /**
  29. * The deviceId of the microphone in use.
  30. */
  31. currentMicDeviceId: string;
  32. /**
  33. * The deviceId of the output device in use.
  34. */
  35. currentOutputDeviceId?: string;
  36. /**
  37. * Flag controlling the visibility of the popup.
  38. */
  39. isOpen: boolean;
  40. /**
  41. * Used to decide whether to measure audio levels for microphone devices.
  42. */
  43. measureAudioLevels: boolean;
  44. /**
  45. * A list with objects containing the labels and deviceIds
  46. * of all the input devices.
  47. */
  48. microphoneDevices: Array<{ deviceId: string; label: string; }>;
  49. /**
  50. * Callback executed when the popup closes.
  51. */
  52. onClose: Function;
  53. /**
  54. * A list of objects containing the labels and deviceIds
  55. * of all the output devices.
  56. */
  57. outputDevices: Array<{ deviceId: string; label: string; }>;
  58. /**
  59. * The popup placement enum value.
  60. */
  61. popupPlacement: string;
  62. /**
  63. * Used to set a new microphone as the current one.
  64. */
  65. setAudioInputDevice: Function;
  66. /**
  67. * Used to set a new output device as the current one.
  68. */
  69. setAudioOutputDevice: Function;
  70. }
  71. const useStyles = makeStyles()(() => {
  72. return {
  73. container: {
  74. display: 'inline-block'
  75. }
  76. };
  77. });
  78. /**
  79. * Popup with audio settings.
  80. *
  81. * @returns {ReactElement}
  82. */
  83. function AudioSettingsPopup({
  84. children,
  85. currentMicDeviceId,
  86. currentOutputDeviceId,
  87. isOpen,
  88. microphoneDevices,
  89. setAudioInputDevice,
  90. setAudioOutputDevice,
  91. onClose,
  92. outputDevices,
  93. popupPlacement,
  94. measureAudioLevels
  95. }: IProps) {
  96. const { classes, cx } = useStyles();
  97. return (
  98. <div className = { cx(classes.container, 'audio-preview') }>
  99. <Popover
  100. allowClick = { true }
  101. content = { <AudioSettingsContent
  102. currentMicDeviceId = { currentMicDeviceId }
  103. currentOutputDeviceId = { currentOutputDeviceId }
  104. measureAudioLevels = { measureAudioLevels }
  105. microphoneDevices = { microphoneDevices }
  106. outputDevices = { outputDevices }
  107. setAudioInputDevice = { setAudioInputDevice }
  108. setAudioOutputDevice = { setAudioOutputDevice } /> }
  109. headingId = 'audio-settings-button'
  110. onPopoverClose = { onClose }
  111. position = { popupPlacement }
  112. trigger = 'click'
  113. visible = { isOpen }>
  114. {children}
  115. </Popover>
  116. </div>
  117. );
  118. }
  119. /**
  120. * Function that maps parts of Redux state tree into component props.
  121. *
  122. * @param {Object} state - Redux state.
  123. * @returns {Object}
  124. */
  125. function mapStateToProps(state: IReduxState) {
  126. const { clientWidth } = state['features/base/responsive-ui'];
  127. return {
  128. popupPlacement: clientWidth <= Number(SMALL_MOBILE_WIDTH) ? 'auto' : 'top-end',
  129. currentMicDeviceId: getCurrentMicDeviceId(state),
  130. currentOutputDeviceId: getCurrentOutputDeviceId(state),
  131. isOpen: Boolean(getAudioSettingsVisibility(state)),
  132. microphoneDevices: getAudioInputDeviceData(state) ?? [],
  133. outputDevices: getAudioOutputDeviceData(state) ?? [],
  134. measureAudioLevels: areAudioLevelsEnabled(state)
  135. };
  136. }
  137. const mapDispatchToProps = {
  138. onClose: toggleAudioSettings,
  139. setAudioInputDevice: setAudioInputDeviceAndUpdateSettings,
  140. setAudioOutputDevice: setAudioOutputDeviceAction
  141. };
  142. export default connect(mapStateToProps, mapDispatchToProps)(AudioSettingsPopup);