2021-06-07 18:19:01 +03:00
|
|
|
// @flow
|
|
|
|
|
|
2021-07-27 17:08:33 +03:00
|
|
|
import Slider from '@react-native-community/slider';
|
2021-06-30 15:21:15 +03:00
|
|
|
import _ from 'lodash';
|
2021-07-01 10:25:29 +03:00
|
|
|
import React, { PureComponent } from 'react';
|
2021-07-27 17:08:33 +03:00
|
|
|
import { View } from 'react-native';
|
2021-06-07 18:19:01 +03:00
|
|
|
import { withTheme } from 'react-native-paper';
|
2023-03-21 09:47:52 +02:00
|
|
|
import { connect } from 'react-redux';
|
2021-06-07 18:19:01 +03:00
|
|
|
|
2022-11-08 12:24:32 +02:00
|
|
|
import { Icon, IconVolumeUp } from '../../../base/icons';
|
2021-07-01 13:12:38 +03:00
|
|
|
import { setVolume } from '../../../participants-pane/actions.native';
|
2021-06-07 18:19:01 +03:00
|
|
|
import { VOLUME_SLIDER_SCALE } from '../../constants';
|
|
|
|
|
|
2021-07-01 17:37:45 +03:00
|
|
|
import styles from './styles';
|
|
|
|
|
|
|
|
|
|
|
2021-06-07 18:19:01 +03:00
|
|
|
/**
|
|
|
|
|
* The type of the React {@code Component} props of {@link VolumeSlider}.
|
|
|
|
|
*/
|
|
|
|
|
type Props = {
|
|
|
|
|
|
|
|
|
|
/**
|
2021-07-01 13:12:38 +03:00
|
|
|
* Whether the participant enters the conference silent.
|
2021-06-07 18:19:01 +03:00
|
|
|
*/
|
2021-07-01 13:12:38 +03:00
|
|
|
_startSilent: boolean,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The volume level for the participant.
|
|
|
|
|
*/
|
|
|
|
|
_volume: number,
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The redux dispatch function.
|
|
|
|
|
*/
|
|
|
|
|
dispatch: Function,
|
|
|
|
|
|
|
|
|
|
/**
|
2021-07-12 18:14:38 +03:00
|
|
|
* The ID of the participant.
|
2021-07-01 13:12:38 +03:00
|
|
|
*/
|
2021-07-12 18:14:38 +03:00
|
|
|
participantID: string,
|
2021-06-07 18:19:01 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Theme used for styles.
|
|
|
|
|
*/
|
2021-06-08 18:58:53 +03:00
|
|
|
theme: Object
|
2021-06-07 18:19:01 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The type of the React {@code Component} state of {@link VolumeSlider}.
|
|
|
|
|
*/
|
|
|
|
|
type State = {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The volume of the participant's audio element. The value will
|
|
|
|
|
* be represented by a slider.
|
|
|
|
|
*/
|
|
|
|
|
volumeLevel: number
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Component that renders the volume slider.
|
|
|
|
|
*
|
|
|
|
|
* @returns {React$Element<any>}
|
|
|
|
|
*/
|
2021-07-01 10:25:29 +03:00
|
|
|
class VolumeSlider extends PureComponent<Props, State> {
|
2021-06-30 15:21:15 +03:00
|
|
|
_onVolumeChange: Function;
|
|
|
|
|
_originalVolumeChange: Function;
|
2021-06-07 18:19:01 +03:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initializes a new {@code VolumeSlider} instance.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} props - The read-only properties with which the new
|
|
|
|
|
* instance is to be initialized.
|
|
|
|
|
*/
|
|
|
|
|
constructor(props: Props) {
|
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
|
|
this.state = {
|
2021-07-01 15:55:06 +03:00
|
|
|
volumeLevel: props._volume || 0
|
2021-06-07 18:19:01 +03:00
|
|
|
};
|
|
|
|
|
|
2021-06-30 15:21:15 +03:00
|
|
|
this._originalVolumeChange = this._onVolumeChange;
|
|
|
|
|
|
|
|
|
|
this._onVolumeChange = _.throttle(
|
|
|
|
|
volumeLevel => this._originalVolumeChange(volumeLevel), 500
|
|
|
|
|
);
|
2021-06-07 18:19:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Implements React's {@link Component#render()}.
|
|
|
|
|
*
|
|
|
|
|
* @inheritdoc
|
|
|
|
|
* @returns {ReactElement}
|
|
|
|
|
*/
|
|
|
|
|
render() {
|
2021-07-01 13:12:38 +03:00
|
|
|
const { _startSilent, theme } = this.props;
|
2021-06-07 18:19:01 +03:00
|
|
|
const { volumeLevel } = this.state;
|
2021-06-08 18:58:53 +03:00
|
|
|
const { palette } = theme;
|
2021-07-01 13:12:38 +03:00
|
|
|
const onVolumeChange = _startSilent ? undefined : this._onVolumeChange;
|
2021-06-07 18:19:01 +03:00
|
|
|
|
|
|
|
|
return (
|
2021-07-01 17:37:45 +03:00
|
|
|
<View style = { styles.volumeSliderContainer } >
|
2021-06-07 18:19:01 +03:00
|
|
|
<Icon
|
2021-07-30 12:46:49 +03:00
|
|
|
size = { 24 }
|
2022-11-08 12:24:32 +02:00
|
|
|
src = { IconVolumeUp } />
|
2021-06-08 17:10:49 +03:00
|
|
|
<Slider
|
2023-03-29 09:20:18 +03:00
|
|
|
maximumTrackTintColor = { palette.ui10 }
|
2021-06-08 17:10:49 +03:00
|
|
|
maximumValue = { VOLUME_SLIDER_SCALE }
|
|
|
|
|
minimumTrackTintColor = { palette.action01 }
|
|
|
|
|
minimumValue = { 0 }
|
2021-07-01 13:12:38 +03:00
|
|
|
onValueChange = { onVolumeChange }
|
2021-07-01 17:37:45 +03:00
|
|
|
style = { styles.sliderContainer }
|
2023-03-29 09:20:18 +03:00
|
|
|
thumbTintColor = { palette.ui10 }
|
2021-06-08 17:10:49 +03:00
|
|
|
value = { volumeLevel } />
|
2021-06-07 18:19:01 +03:00
|
|
|
</View>
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the internal state of the volume level for the volume slider.
|
|
|
|
|
* Invokes the prop onVolumeChange to notify of volume changes.
|
|
|
|
|
*
|
|
|
|
|
* @param {number} volumeLevel - Selected volume on slider.
|
|
|
|
|
* @private
|
|
|
|
|
* @returns {void}
|
|
|
|
|
*/
|
|
|
|
|
_onVolumeChange(volumeLevel) {
|
2021-07-13 16:17:20 +03:00
|
|
|
const { dispatch, participantID } = this.props;
|
2021-07-01 13:12:38 +03:00
|
|
|
|
2021-07-13 16:17:20 +03:00
|
|
|
dispatch(setVolume(participantID, volumeLevel));
|
2021-06-07 18:19:01 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-01 13:12:38 +03:00
|
|
|
/**
|
|
|
|
|
* Maps (parts of) the Redux state to the associated props for the
|
|
|
|
|
* {@code VolumeSlider} component.
|
|
|
|
|
*
|
|
|
|
|
* @param {Object} state - The Redux state.
|
|
|
|
|
* @param {Object} ownProps - The own props of the component.
|
|
|
|
|
* @returns {Props}
|
|
|
|
|
*/
|
|
|
|
|
function mapStateToProps(state, ownProps): Object {
|
2021-07-12 18:14:38 +03:00
|
|
|
const { participantID } = ownProps;
|
2021-07-01 13:12:38 +03:00
|
|
|
const { participantsVolume } = state['features/participants-pane'];
|
2021-07-02 16:43:52 +03:00
|
|
|
const { startSilent } = state['features/base/config'];
|
2021-07-01 13:12:38 +03:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
_startSilent: Boolean(startSilent),
|
2021-07-30 12:46:49 +03:00
|
|
|
_volume: participantID && participantsVolume[participantID]
|
2021-07-01 13:12:38 +03:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-12 18:14:38 +03:00
|
|
|
export default connect(mapStateToProps)(withTheme(VolumeSlider));
|
2021-06-07 18:19:01 +03:00
|
|
|
|