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

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