2023-02-13 14:01:08 +00:00
|
|
|
import React, { ReactNode } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
2020-03-30 14:17:18 +00:00
|
|
|
|
2023-02-13 14:01:08 +00:00
|
|
|
import { IReduxState } from '../../../../app/types';
|
|
|
|
import { areAudioLevelsEnabled } from '../../../../base/config/functions.web';
|
2020-03-30 14:17:18 +00:00
|
|
|
import {
|
2020-04-14 06:53:04 +00:00
|
|
|
setAudioInputDeviceAndUpdateSettings,
|
2020-03-30 14:17:18 +00:00
|
|
|
setAudioOutputDevice as setAudioOutputDeviceAction
|
2022-11-01 12:36:32 +00:00
|
|
|
} from '../../../../base/devices/actions.web';
|
|
|
|
import {
|
|
|
|
getAudioInputDeviceData,
|
|
|
|
getAudioOutputDeviceData
|
|
|
|
} from '../../../../base/devices/functions.web';
|
2022-10-27 08:03:28 +00:00
|
|
|
import Popover from '../../../../base/popover/components/Popover.web';
|
2021-06-30 09:01:47 +00:00
|
|
|
import { SMALL_MOBILE_WIDTH } from '../../../../base/responsive-ui/constants';
|
2020-03-30 14:17:18 +00:00
|
|
|
import {
|
|
|
|
getCurrentMicDeviceId,
|
|
|
|
getCurrentOutputDeviceId
|
2023-02-13 14:01:08 +00:00
|
|
|
} from '../../../../base/settings/functions.web';
|
2020-05-20 10:57:03 +00:00
|
|
|
import { toggleAudioSettings } from '../../../actions';
|
2023-02-13 14:01:08 +00:00
|
|
|
import { getAudioSettingsVisibility } from '../../../functions.web';
|
2020-05-20 10:57:03 +00:00
|
|
|
|
2023-02-13 14:01:08 +00:00
|
|
|
import AudioSettingsContent, { type IProps as AudioSettingsContentProps } from './AudioSettingsContent';
|
2020-03-30 14:17:18 +00:00
|
|
|
|
|
|
|
|
2023-02-13 14:01:08 +00:00
|
|
|
interface IProps extends AudioSettingsContentProps {
|
2020-03-30 14:17:18 +00:00
|
|
|
|
2022-10-27 08:03:28 +00:00
|
|
|
/**
|
2020-03-30 14:17:18 +00:00
|
|
|
* Component's children (the audio button).
|
|
|
|
*/
|
2023-02-13 14:01:08 +00:00
|
|
|
children: ReactNode;
|
2020-03-30 14:17:18 +00:00
|
|
|
|
2022-10-27 08:03:28 +00:00
|
|
|
/**
|
2020-03-30 14:17:18 +00:00
|
|
|
* Flag controlling the visibility of the popup.
|
|
|
|
*/
|
2023-02-13 14:01:08 +00:00
|
|
|
isOpen: boolean;
|
2020-03-30 14:17:18 +00:00
|
|
|
|
2022-10-27 08:03:28 +00:00
|
|
|
/**
|
2020-03-30 14:17:18 +00:00
|
|
|
* Callback executed when the popup closes.
|
|
|
|
*/
|
2023-02-13 14:01:08 +00:00
|
|
|
onClose: Function;
|
2021-06-30 09:01:47 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The popup placement enum value.
|
|
|
|
*/
|
2023-02-13 14:01:08 +00:00
|
|
|
popupPlacement: string;
|
2020-03-30 14:17:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Popup with audio settings.
|
|
|
|
*
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
function AudioSettingsPopup({
|
|
|
|
children,
|
|
|
|
currentMicDeviceId,
|
|
|
|
currentOutputDeviceId,
|
|
|
|
isOpen,
|
|
|
|
microphoneDevices,
|
|
|
|
setAudioInputDevice,
|
|
|
|
setAudioOutputDevice,
|
|
|
|
onClose,
|
2021-06-30 09:01:47 +00:00
|
|
|
outputDevices,
|
2022-01-11 16:08:36 +00:00
|
|
|
popupPlacement,
|
|
|
|
measureAudioLevels
|
2023-02-13 14:01:08 +00:00
|
|
|
}: IProps) {
|
2020-03-30 14:17:18 +00:00
|
|
|
return (
|
|
|
|
<div className = 'audio-preview'>
|
2022-10-27 08:03:28 +00:00
|
|
|
<Popover
|
2020-03-30 14:17:18 +00:00
|
|
|
content = { <AudioSettingsContent
|
|
|
|
currentMicDeviceId = { currentMicDeviceId }
|
|
|
|
currentOutputDeviceId = { currentOutputDeviceId }
|
2022-01-11 16:08:36 +00:00
|
|
|
measureAudioLevels = { measureAudioLevels }
|
2020-03-30 14:17:18 +00:00
|
|
|
microphoneDevices = { microphoneDevices }
|
|
|
|
outputDevices = { outputDevices }
|
|
|
|
setAudioInputDevice = { setAudioInputDevice }
|
|
|
|
setAudioOutputDevice = { setAudioOutputDevice } /> }
|
2022-10-27 08:03:28 +00:00
|
|
|
onPopoverClose = { onClose }
|
|
|
|
position = { popupPlacement }
|
|
|
|
trigger = 'click'
|
|
|
|
visible = { isOpen }>
|
2020-03-30 14:17:18 +00:00
|
|
|
{children}
|
2022-10-27 08:03:28 +00:00
|
|
|
</Popover>
|
2020-03-30 14:17:18 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function that maps parts of Redux state tree into component props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - Redux state.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2023-02-13 14:01:08 +00:00
|
|
|
function mapStateToProps(state: IReduxState) {
|
2021-06-30 09:01:47 +00:00
|
|
|
const { clientWidth } = state['features/base/responsive-ui'];
|
|
|
|
|
2020-03-30 14:17:18 +00:00
|
|
|
return {
|
2023-02-13 14:01:08 +00:00
|
|
|
popupPlacement: clientWidth <= Number(SMALL_MOBILE_WIDTH) ? 'auto' : 'top-end',
|
2020-03-30 14:17:18 +00:00
|
|
|
currentMicDeviceId: getCurrentMicDeviceId(state),
|
|
|
|
currentOutputDeviceId: getCurrentOutputDeviceId(state),
|
2023-02-13 14:01:08 +00:00
|
|
|
isOpen: Boolean(getAudioSettingsVisibility(state)),
|
|
|
|
microphoneDevices: getAudioInputDeviceData(state) ?? [],
|
|
|
|
outputDevices: getAudioOutputDeviceData(state) ?? [],
|
2022-01-11 16:08:36 +00:00
|
|
|
measureAudioLevels: areAudioLevelsEnabled(state)
|
2020-03-30 14:17:18 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = {
|
|
|
|
onClose: toggleAudioSettings,
|
2020-04-14 06:53:04 +00:00
|
|
|
setAudioInputDevice: setAudioInputDeviceAndUpdateSettings,
|
2020-03-30 14:17:18 +00:00
|
|
|
setAudioOutputDevice: setAudioOutputDeviceAction
|
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(AudioSettingsPopup);
|