2018-10-30 05:02:23 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2017-05-31 15:42:50 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
|
2019-08-30 16:39:06 +00:00
|
|
|
import { Icon, IconVolume } from '../../../base/icons';
|
|
|
|
|
2017-05-31 15:42:50 +00:00
|
|
|
/**
|
|
|
|
* Used to modify initialValue, which is expected to be a decimal value between
|
|
|
|
* 0 and 1, and converts it to a number representable by an input slider, which
|
|
|
|
* recognizes whole numbers.
|
|
|
|
*/
|
|
|
|
const VOLUME_SLIDER_SCALE = 100;
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
type Props = {
|
|
|
|
|
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
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
initialValue: number,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The callback to invoke when the audio slider value changes.
|
|
|
|
*/
|
|
|
|
onChange: Function
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
volumeLevel: number
|
|
|
|
};
|
2017-05-31 15:42:50 +00:00
|
|
|
|
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.
|
|
|
|
*
|
|
|
|
* @extends Component
|
|
|
|
*/
|
|
|
|
class VolumeSlider extends Component<Props, 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.
|
|
|
|
*/
|
2018-10-30 05:02:23 +00:00
|
|
|
constructor(props: Props) {
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
*
|
|
|
|
* @inheritdoc
|
|
|
|
* @returns {ReactElement}
|
|
|
|
*/
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<li className = 'popupmenu__item'>
|
|
|
|
<div className = 'popupmenu__contents'>
|
|
|
|
<span className = 'popupmenu__icon'>
|
2019-08-30 16:39:06 +00:00
|
|
|
<Icon src = { IconVolume } />
|
2017-05-31 15:42:50 +00:00
|
|
|
</span>
|
|
|
|
<div className = 'popupmenu__slider_container'>
|
|
|
|
<input
|
|
|
|
className = 'popupmenu__slider'
|
|
|
|
max = { VOLUME_SLIDER_SCALE }
|
|
|
|
min = { 0 }
|
|
|
|
onChange = { this._onVolumeChange }
|
|
|
|
type = 'range'
|
|
|
|
value = { this.state.volumeLevel } />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-10-30 05:02:23 +00:00
|
|
|
_onVolumeChange: (Object) => void;
|
|
|
|
|
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}
|
|
|
|
*/
|
|
|
|
_onVolumeChange(event) {
|
|
|
|
const volumeLevel = event.currentTarget.value;
|
|
|
|
|
|
|
|
this.props.onChange(volumeLevel / VOLUME_SLIDER_SCALE);
|
|
|
|
this.setState({ volumeLevel });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default VolumeSlider;
|