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.

AudioSettingsPopup.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // @flow
  2. import React from 'react';
  3. import { areAudioLevelsEnabled } from '../../../../base/config/functions';
  4. import {
  5. setAudioInputDeviceAndUpdateSettings,
  6. setAudioOutputDevice as setAudioOutputDeviceAction
  7. } from '../../../../base/devices/actions.web';
  8. import {
  9. getAudioInputDeviceData,
  10. getAudioOutputDeviceData
  11. } from '../../../../base/devices/functions.web';
  12. import Popover from '../../../../base/popover/components/Popover.web';
  13. import { connect } from '../../../../base/redux';
  14. import { SMALL_MOBILE_WIDTH } from '../../../../base/responsive-ui/constants';
  15. import {
  16. getCurrentMicDeviceId,
  17. getCurrentOutputDeviceId
  18. } from '../../../../base/settings';
  19. import { toggleAudioSettings } from '../../../actions';
  20. import { getAudioSettingsVisibility } from '../../../functions';
  21. import AudioSettingsContent, { type Props as AudioSettingsContentProps } from './AudioSettingsContent';
  22. type Props = AudioSettingsContentProps & {
  23. /**
  24. * Component's children (the audio button).
  25. */
  26. children: React$Node,
  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. }: Props) {
  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. onPopoverClose = { onClose }
  70. position = { popupPlacement }
  71. trigger = 'click'
  72. visible = { isOpen }>
  73. {children}
  74. </Popover>
  75. </div>
  76. );
  77. }
  78. /**
  79. * Function that maps parts of Redux state tree into component props.
  80. *
  81. * @param {Object} state - Redux state.
  82. * @returns {Object}
  83. */
  84. function mapStateToProps(state) {
  85. const { clientWidth } = state['features/base/responsive-ui'];
  86. return {
  87. popupPlacement: clientWidth <= SMALL_MOBILE_WIDTH ? 'auto' : 'top-end',
  88. currentMicDeviceId: getCurrentMicDeviceId(state),
  89. currentOutputDeviceId: getCurrentOutputDeviceId(state),
  90. isOpen: getAudioSettingsVisibility(state),
  91. microphoneDevices: getAudioInputDeviceData(state),
  92. outputDevices: getAudioOutputDeviceData(state),
  93. measureAudioLevels: areAudioLevelsEnabled(state)
  94. };
  95. }
  96. const mapDispatchToProps = {
  97. onClose: toggleAudioSettings,
  98. setAudioInputDevice: setAudioInputDeviceAndUpdateSettings,
  99. setAudioOutputDevice: setAudioOutputDeviceAction
  100. };
  101. export default connect(mapStateToProps, mapDispatchToProps)(AudioSettingsPopup);