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

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