2022-09-13 07:36:00 +00:00
|
|
|
import { Theme } from '@mui/material';
|
|
|
|
import { withStyles } from '@mui/styles';
|
2021-12-15 13:18:41 +00:00
|
|
|
import clsx from 'clsx';
|
2017-05-31 15:42:50 +00:00
|
|
|
import React, { Component } from 'react';
|
2022-08-25 11:35:19 +00:00
|
|
|
import { WithTranslation } from 'react-i18next';
|
2017-05-31 15:42:50 +00:00
|
|
|
|
2022-08-25 11:35:19 +00:00
|
|
|
import { translate } from '../../../base/i18n/functions';
|
|
|
|
import Icon from '../../../base/icons/components/Icon';
|
2022-09-06 17:32:20 +00:00
|
|
|
import { IconVolume } from '../../../base/icons/svg';
|
2021-06-07 15:19:01 +00:00
|
|
|
import { VOLUME_SLIDER_SCALE } from '../../constants';
|
2017-05-31 15:42:50 +00:00
|
|
|
|
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* The type of the React {@code Component} props of {@link VolumeSlider}.
|
2017-05-31 15:42:50 +00:00
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
interface IProps extends WithTranslation {
|
2018-10-30 05:02:23 +00:00
|
|
|
|
2021-12-15 13:18:41 +00:00
|
|
|
/**
|
|
|
|
* An object containing the CSS classes.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
classes: any;
|
2021-12-15 13:18:41 +00:00
|
|
|
|
2017-05-31 15:42:50 +00:00
|
|
|
/**
|
2018-10-30 05:02:23 +00:00
|
|
|
* The value of the audio slider should display at when the component first
|
|
|
|
* mounts. Changes will be stored in state. The value should be a number
|
|
|
|
* between 0 and 1.
|
2017-05-31 15:42:50 +00:00
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
initialValue: number;
|
2018-10-30 05:02:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The callback to invoke when the audio slider value changes.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
onChange: Function;
|
2022-08-25 11:35:19 +00:00
|
|
|
}
|
2018-10-30 05:02:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The type of the React {@code Component} state of {@link VolumeSlider}.
|
|
|
|
*/
|
|
|
|
type State = {
|
2017-05-31 15:42:50 +00:00
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* The volume of the participant's audio element. The value will
|
|
|
|
* be represented by a slider.
|
|
|
|
*/
|
2022-09-08 09:52:36 +00:00
|
|
|
volumeLevel: number;
|
2018-10-30 05:02:23 +00:00
|
|
|
};
|
2017-05-31 15:42:50 +00:00
|
|
|
|
2022-09-13 07:36:00 +00:00
|
|
|
const styles = (theme: Theme) => {
|
2021-12-15 13:18:41 +00:00
|
|
|
return {
|
|
|
|
container: {
|
|
|
|
minHeight: '40px',
|
2022-01-19 14:01:51 +00:00
|
|
|
minWidth: '180px',
|
2021-12-15 13:18:41 +00:00
|
|
|
width: '100%',
|
2022-09-13 07:36:00 +00:00
|
|
|
boxSizing: 'border-box' as const,
|
2021-12-15 13:18:41 +00:00
|
|
|
cursor: 'pointer',
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
padding: '0 5px',
|
|
|
|
|
|
|
|
'&:hover': {
|
|
|
|
backgroundColor: theme.palette.ui04
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
icon: {
|
|
|
|
minWidth: '20px',
|
|
|
|
padding: '5px',
|
2022-09-13 07:36:00 +00:00
|
|
|
position: 'relative' as const
|
2021-12-15 13:18:41 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
sliderContainer: {
|
2022-09-13 07:36:00 +00:00
|
|
|
position: 'relative' as const,
|
2021-12-15 13:18:41 +00:00
|
|
|
width: '100%',
|
|
|
|
paddingRight: '5px'
|
|
|
|
},
|
|
|
|
|
|
|
|
slider: {
|
2022-09-13 07:36:00 +00:00
|
|
|
position: 'absolute' as const,
|
2021-12-15 13:18:41 +00:00
|
|
|
width: '100%',
|
|
|
|
top: '50%',
|
|
|
|
transform: 'translate(0, -50%)'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
/**
|
|
|
|
* Implements a React {@link Component} which displays an input slider for
|
|
|
|
* adjusting the local volume of a remote participant.
|
|
|
|
*
|
2021-11-04 21:10:43 +00:00
|
|
|
* @augments Component
|
2018-10-30 05:02:23 +00:00
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
class VolumeSlider extends Component<IProps, State> {
|
2017-05-31 15:42:50 +00:00
|
|
|
/**
|
|
|
|
* Initializes a new {@code VolumeSlider} instance.
|
|
|
|
*
|
|
|
|
* @param {Object} props - The read-only properties with which the new
|
|
|
|
* instance is to be initialized.
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
constructor(props: IProps) {
|
2017-05-31 15:42:50 +00:00
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
volumeLevel: (props.initialValue || 0) * VOLUME_SLIDER_SCALE
|
|
|
|
};
|
|
|
|
|
|
|
|
// Bind event handlers so they are only bound once for every instance.
|
|
|
|
this._onVolumeChange = this._onVolumeChange.bind(this);
|
|
|
|
}
|
|
|
|
|
2021-12-15 13:18:41 +00:00
|
|
|
/**
|
|
|
|
* Click handler.
|
|
|
|
*
|
|
|
|
* @param {MouseEvent} e - Click event.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-08-25 11:35:19 +00:00
|
|
|
_onClick(e: React.MouseEvent) {
|
2021-12-15 13:18:41 +00:00
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
|
2017-05-31 15:42:50 +00:00
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
2021-12-15 13:18:41 +00:00
|
|
|
const { classes } = this.props;
|
|
|
|
|
2017-05-31 15:42:50 +00:00
|
|
|
return (
|
2021-12-15 13:18:41 +00:00
|
|
|
<div
|
2021-06-10 12:48:44 +00:00
|
|
|
aria-label = { this.props.t('volumeSlider') }
|
2021-12-15 13:18:41 +00:00
|
|
|
className = { clsx('popupmenu__contents', classes.container) }
|
|
|
|
onClick = { this._onClick }>
|
|
|
|
<span className = { classes.icon }>
|
|
|
|
<Icon
|
|
|
|
size = { 22 }
|
|
|
|
src = { IconVolume } />
|
|
|
|
</span>
|
|
|
|
<div className = { classes.sliderContainer }>
|
|
|
|
<input
|
|
|
|
aria-valuemax = { VOLUME_SLIDER_SCALE }
|
|
|
|
aria-valuemin = { 0 }
|
|
|
|
aria-valuenow = { this.state.volumeLevel }
|
|
|
|
className = { clsx('popupmenu__volume-slider', classes.slider) }
|
|
|
|
max = { VOLUME_SLIDER_SCALE }
|
|
|
|
min = { 0 }
|
|
|
|
onChange = { this._onVolumeChange }
|
|
|
|
tabIndex = { 0 }
|
|
|
|
type = 'range'
|
|
|
|
value = { this.state.volumeLevel } />
|
2017-05-31 15:42:50 +00:00
|
|
|
</div>
|
2021-12-15 13:18:41 +00:00
|
|
|
</div>
|
2017-05-31 15:42:50 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the internal state of the volume level for the volume slider.
|
|
|
|
* Invokes the prop onVolumeChange to notify of volume changes.
|
|
|
|
*
|
|
|
|
* @param {Object} event - DOM Event for slider change.
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
2022-08-25 11:35:19 +00:00
|
|
|
_onVolumeChange(event: React.ChangeEvent<HTMLInputElement>) {
|
|
|
|
const volumeLevel = Number(event.currentTarget.value);
|
2017-05-31 15:42:50 +00:00
|
|
|
|
|
|
|
this.props.onChange(volumeLevel / VOLUME_SLIDER_SCALE);
|
|
|
|
this.setState({ volumeLevel });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-15 13:18:41 +00:00
|
|
|
export default translate(withStyles(styles)(VolumeSlider));
|