Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

AudioSettingsPopup.tsx 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import React, { ReactNode } from 'react';
  2. import { connect } from 'react-redux';
  3. import { IReduxState } from '../../../../app/types';
  4. import { areAudioLevelsEnabled } from '../../../../base/config/functions.web';
  5. import {
  6. setAudioInputDeviceAndUpdateSettings,
  7. setAudioOutputDevice as setAudioOutputDeviceAction
  8. } from '../../../../base/devices/actions.web';
  9. import {
  10. getAudioInputDeviceData,
  11. getAudioOutputDeviceData
  12. } from '../../../../base/devices/functions.web';
  13. import Popover from '../../../../base/popover/components/Popover.web';
  14. import { SMALL_MOBILE_WIDTH } from '../../../../base/responsive-ui/constants';
  15. import {
  16. getCurrentMicDeviceId,
  17. getCurrentOutputDeviceId
  18. } from '../../../../base/settings/functions.web';
  19. import { toggleAudioSettings } from '../../../actions';
  20. import { getAudioSettingsVisibility } from '../../../functions.web';
  21. import AudioSettingsContent, { type IProps as AudioSettingsContentProps } from './AudioSettingsContent';
  22. interface IProps extends AudioSettingsContentProps {
  23. /**
  24. * Component's children (the audio button).
  25. */
  26. children: ReactNode;
  27. /**
  28. * Flag controlling the visibility of the popup.
  29. */
  30. isOpen: boolean;
  31. /**
  32. * Callback executed when the popup closes.
  33. */
  34. onClose: Function;
  35. /**
  36. * The popup placement enum value.
  37. */
  38. popupPlacement: string;
  39. }
  40. /**
  41. * Popup with audio settings.
  42. *
  43. * @returns {ReactElement}
  44. */
  45. function AudioSettingsPopup({
  46. children,
  47. currentMicDeviceId,
  48. currentOutputDeviceId,
  49. isOpen,
  50. microphoneDevices,
  51. setAudioInputDevice,
  52. setAudioOutputDevice,
  53. onClose,
  54. outputDevices,
  55. popupPlacement,
  56. measureAudioLevels
  57. }: IProps) {
  58. return (
  59. <div className = 'audio-preview'>
  60. <Popover
  61. content = { <AudioSettingsContent
  62. currentMicDeviceId = { currentMicDeviceId }
  63. currentOutputDeviceId = { currentOutputDeviceId }
  64. measureAudioLevels = { measureAudioLevels }
  65. microphoneDevices = { microphoneDevices }
  66. outputDevices = { outputDevices }
  67. setAudioInputDevice = { setAudioInputDevice }
  68. setAudioOutputDevice = { setAudioOutputDevice } /> }
  69. headingId = 'audio-settings-button'
  70. onPopoverClose = { onClose }
  71. position = { popupPlacement }
  72. trigger = 'click'
  73. visible = { isOpen }>
  74. {children}
  75. </Popover>
  76. </div>
  77. );
  78. }
  79. /**
  80. * Function that maps parts of Redux state tree into component props.
  81. *
  82. * @param {Object} state - Redux state.
  83. * @returns {Object}
  84. */
  85. function mapStateToProps(state: IReduxState) {
  86. const { clientWidth } = state['features/base/responsive-ui'];
  87. return {
  88. popupPlacement: clientWidth <= Number(SMALL_MOBILE_WIDTH) ? 'auto' : 'top-end',
  89. currentMicDeviceId: getCurrentMicDeviceId(state),
  90. currentOutputDeviceId: getCurrentOutputDeviceId(state),
  91. isOpen: Boolean(getAudioSettingsVisibility(state)),
  92. microphoneDevices: getAudioInputDeviceData(state) ?? [],
  93. outputDevices: getAudioOutputDeviceData(state) ?? [],
  94. measureAudioLevels: areAudioLevelsEnabled(state)
  95. };
  96. }
  97. const mapDispatchToProps = {
  98. onClose: toggleAudioSettings,
  99. setAudioInputDevice: setAudioInputDeviceAndUpdateSettings,
  100. setAudioOutputDevice: setAudioOutputDeviceAction
  101. };
  102. export default connect(mapStateToProps, mapDispatchToProps)(AudioSettingsPopup);