Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat(video-menu): native track volume control updates (#13305)

Calinteodoreafb337cd132
diff --git a/react/features/video-menu/components/native/RemoteVideoMenu.tsx b/react/features/video-menu/components/native/RemoteVideoMenu.tsx
index fe707ad735..37c9c9ee15 100644
--- a/react/features/video-menu/components/native/RemoteVideoMenu.tsx
+++ b/react/features/video-menu/components/native/RemoteVideoMenu.tsx
@@ -1,3 +1,5 @@
+/* eslint-disable lines-around-comment*/
+
import React, { PureComponent } from 'react';
import { Text, TextStyle, View, ViewStyle } from 'react-native';
import { Divider } from 'react-native-paper';
@@ -29,9 +31,9 @@ import MuteEveryoneElseButton from './MuteEveryoneElseButton';
import MuteVideoButton from './MuteVideoButton';
import PinButton from './PinButton';
import SendToBreakoutRoom from './SendToBreakoutRoom';
+import VolumeSlider from './VolumeSlider';
import styles from './styles';
-// import VolumeSlider from './VolumeSlider';
/**
* Size of the rendered avatar in the menu.
@@ -142,6 +144,11 @@ class RemoteVideoMenu extends PureComponent<IProps> {
styles: bottomSheetStyles.buttons
};
+ const connectionStatusButtonProps = {
+ ...buttonProps,
+ afterClick: undefined
+ };
+
return (
<BottomSheet
renderHeader = { this._renderMenuHeader }
@@ -156,9 +163,7 @@ class RemoteVideoMenu extends PureComponent<IProps> {
{ !_disableGrantModerator && <GrantModeratorButton { ...buttonProps } /> }
<PinButton { ...buttonProps } />
{ !_disablePrivateChat && <PrivateMessageButton { ...buttonProps } /> }
- <ConnectionStatusButton
- { ...buttonProps }
- afterClick = { undefined } />
+ <ConnectionStatusButton { ...connectionStatusButtonProps } />
{_moderator && _rooms.length > 1 && <>
{/* @ts-ignore */}
<Divider style = { styles.divider as ViewStyle } />
@@ -172,7 +177,7 @@ class RemoteVideoMenu extends PureComponent<IProps> {
room = { room }
{ ...buttonProps } />))}
</>}
- {/* <VolumeSlider participantID = { participantId } />*/}
+ <VolumeSlider participantID = { participantId } />
</BottomSheet>
);
}
diff --git a/react/features/video-menu/components/native/VolumeSlider.tsx b/react/features/video-menu/components/native/VolumeSlider.tsx
index 142b209d6b..4f78c78ac0 100644
--- a/react/features/video-menu/components/native/VolumeSlider.tsx
+++ b/react/features/video-menu/components/native/VolumeSlider.tsx
@@ -1,18 +1,26 @@
+/* eslint-disable lines-around-comment*/
+
import Slider from '@react-native-community/slider';
import _ from 'lodash';
import React, { PureComponent } from 'react';
import { View, ViewStyle } from 'react-native';
-import { withTheme } from 'react-native-paper';
import { connect } from 'react-redux';
import { IReduxState } from '../../../app/types';
import Icon from '../../../base/icons/components/Icon';
import { IconVolumeUp } from '../../../base/icons/svg';
+import { MEDIA_TYPE } from '../../../base/media/constants';
+import {
+ getTrackByMediaTypeAndParticipant,
+ getTrackState
+} from '../../../base/tracks/functions.native';
+import BaseTheme from '../../../base/ui/components/BaseTheme.native';
import { setVolume } from '../../../participants-pane/actions.native';
-import { VOLUME_SLIDER_SCALE } from '../../constants';
+import { NATIVE_VOLUME_SLIDER_SCALE } from '../../constants';
import styles from './styles';
+
/**
* The type of the React {@code Component} props of {@link VolumeSlider}.
*/
@@ -21,27 +29,27 @@ interface IProps {
/**
* Whether the participant enters the conference silent.
*/
- _startSilent: boolean;
+ _startSilent?: boolean;
/**
- * The volume level for the participant.
+ * Remote audio track.
*/
- _volume: number;
+ _track?: any;
/**
- * The redux dispatch function.
+ * The volume level for the participant.
*/
- dispatch: Function;
+ _volume?: number;
/**
- * The ID of the participant.
+ * The redux dispatch function.
*/
- participantID: string;
+ dispatch?: Function;
/**
- * Theme used for styles.
+ * The ID of the participant.
*/
- theme: any;
+ participantID?: string;
}
/**
@@ -62,6 +70,7 @@ interface IState {
* @returns {React$Element<any>}
*/
class VolumeSlider extends PureComponent<IProps, IState> {
+
_originalVolumeChange: Function;
/**
@@ -74,7 +83,7 @@ class VolumeSlider extends PureComponent<IProps, IState> {
super(props);
this.state = {
- volumeLevel: props._volume || 0
+ volumeLevel: props._volume || Math.ceil(NATIVE_VOLUME_SLIDER_SCALE / 2)
};
this._originalVolumeChange = this._onVolumeChange;
@@ -91,9 +100,8 @@ class VolumeSlider extends PureComponent<IProps, IState> {
* @returns {ReactElement}
*/
render() {
- const { _startSilent, theme } = this.props;
+ const { _startSilent } = this.props;
const { volumeLevel } = this.state;
- const { palette } = theme;
const onVolumeChange = _startSilent ? undefined : this._onVolumeChange;
return (
@@ -102,13 +110,13 @@ class VolumeSlider extends PureComponent<IProps, IState> {
size = { 24 }
src = { IconVolumeUp } />
<Slider
- maximumTrackTintColor = { palette.ui10 }
- maximumValue = { VOLUME_SLIDER_SCALE }
- minimumTrackTintColor = { palette.action01 }
+ maximumTrackTintColor = { BaseTheme.palette.ui10 }
+ maximumValue = { NATIVE_VOLUME_SLIDER_SCALE }
+ minimumTrackTintColor = { BaseTheme.palette.action01 }
minimumValue = { 0 }
onValueChange = { onVolumeChange }
style = { styles.sliderContainer as ViewStyle }
- thumbTintColor = { palette.ui10 }
+ thumbTintColor = { BaseTheme.palette.ui10 }
value = { volumeLevel } />
</View>
@@ -123,10 +131,22 @@ class VolumeSlider extends PureComponent<IProps, IState> {
* @private
* @returns {void}
*/
- _onVolumeChange(volumeLevel: number) {
- const { dispatch, participantID } = this.props;
+ _onVolumeChange(volumeLevel: any) {
+ const { _track, dispatch, participantID } = this.props;
+ const audioTrack = _track?.jitsiTrack.track;
+
+ let newVolumeLevel;
- dispatch(setVolume(participantID, volumeLevel));
+ if (volumeLevel <= 10) {
+ newVolumeLevel = volumeLevel / 10;
+ } else {
+ newVolumeLevel = volumeLevel - 9;
+ }
+
+ audioTrack?._setVolume(newVolumeLevel);
+
+ // @ts-ignore
+ dispatch(setVolume(participantID, newVolumeLevel));
}
}
@@ -138,16 +158,18 @@ class VolumeSlider extends PureComponent<IProps, IState> {
* @param {Object} ownProps - The own props of the component.
* @returns {IProps}
*/
-function mapStateToProps(state: IReduxState, ownProps: any) {
+function mapStateToProps(state: IReduxState, ownProps: IProps) {
const { participantID } = ownProps;
- const { participantsVolume } = state['features/participants-pane'];
+ const { participantsVolume } = state['features/filmstrip'];
const { startSilent } = state['features/base/config'];
+ const tracks = getTrackState(state);
return {
_startSilent: Boolean(startSilent),
+ _track: getTrackByMediaTypeAndParticipant(tracks, MEDIA_TYPE.AUDIO, participantID),
_volume: participantID && participantsVolume[participantID]
};
}
-export default connect(mapStateToProps)(withTheme(VolumeSlider));
-
+// @ts-ignore
+export default connect(mapStateToProps)(VolumeSlider);
diff --git a/react/features/video-menu/constants.ts b/react/features/video-menu/constants.ts
index 523a47bfd2..a293bd3622 100644
--- a/react/features/video-menu/constants.ts
+++ b/react/features/video-menu/constants.ts
@@ -1,3 +1,11 @@
+/**
+ * Used to set maximumValue for native volume slider.
+ * Slider double-precision floating-point number indicating the volume,
+ * from 0 mute to 1 max, which converts to 0 mute to 19 max in our case.
+ * 0 as muted, 10 as standard and 19 as max remote participant volume level.
+ */
+export const NATIVE_VOLUME_SLIDER_SCALE = 19;
+
/**
* 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