Просмотр исходного кода

feat(native-participants-pane) volume slider refactoring

master
Calin Chitu 4 лет назад
Родитель
Сommit
5182a720f9

+ 0
- 10
react/features/base/config/functions.any.js Просмотреть файл

@@ -60,16 +60,6 @@ export function getRecordingSharingUrl(state: Object) {
60 60
     return state['features/base/config'].recordingSharingUrl;
61 61
 }
62 62
 
63
-/**
64
- * Selector used to get if the new participant is starting silent.
65
- *
66
- * @param {Object} state - The global state.
67
- * @returns {string}
68
- */
69
-export function getIsStartingSilent(state: Object) {
70
-    return Boolean(state['features/base/config'].startSilent);
71
-}
72
-
73 63
 /**
74 64
  * Overrides JSON properties in {@code config} and
75 65
  * {@code interfaceConfig} Objects with the values from {@code newConfig}.

+ 5
- 0
react/features/participants-pane/actionTypes.js Просмотреть файл

@@ -7,3 +7,8 @@ export const PARTICIPANTS_PANE_CLOSE = 'PARTICIPANTS_PANE_CLOSE';
7 7
  * Action type to signal the opening of the participants pane.
8 8
  */
9 9
 export const PARTICIPANTS_PANE_OPEN = 'PARTICIPANTS_PANE_OPEN';
10
+
11
+/**
12
+ * Action type to set the volume of the participant.
13
+ */
14
+export const SET_VOLUME = 'SET_VOLUME';

+ 20
- 0
react/features/participants-pane/actions.native.js Просмотреть файл

@@ -2,6 +2,7 @@
2 2
 
3 3
 import { openDialog } from '../base/dialog';
4 4
 
5
+import { SET_VOLUME } from './actionTypes';
5 6
 import { ContextMenuLobbyParticipantReject, ContextMenuMeetingParticipantDetails } from './components/native';
6 7
 export * from './actions.any';
7 8
 
@@ -25,3 +26,22 @@ export function showContextMenuReject(participant: Object) {
25 26
 export function showContextMenuDetails(participant: Object) {
26 27
     return openDialog(ContextMenuMeetingParticipantDetails, { participant });
27 28
 }
29
+
30
+/**
31
+ * Sets the volume.
32
+ *
33
+ * @param {string} participantId - The participant ID associated with the audio.
34
+ * @param {string} volume - The volume level.
35
+ * @returns {{
36
+ *     type: SET_VOLUME,
37
+ *     participantId: string,
38
+ *     volume: number
39
+ * }}
40
+ */
41
+export function setVolume(participantId: string, volume: number) {
42
+    return {
43
+        type: SET_VOLUME,
44
+        participantId,
45
+        volume
46
+    };
47
+}

+ 1
- 6
react/features/participants-pane/components/native/ContextMenuMeetingParticipantDetails.js Просмотреть файл

@@ -7,7 +7,6 @@ import { Divider, Text } from 'react-native-paper';
7 7
 import { useDispatch, useSelector } from 'react-redux';
8 8
 
9 9
 import { Avatar } from '../../../base/avatar';
10
-import { getIsStartingSilent } from '../../../base/config';
11 10
 import { hideDialog, openDialog } from '../../../base/dialog/actions';
12 11
 import BottomSheet from '../../../base/dialog/components/native/BottomSheet';
13 12
 import {
@@ -41,9 +40,6 @@ type Props = {
41 40
 export const ContextMenuMeetingParticipantDetails = ({ participant: p }: Props) => {
42 41
     const dispatch = useDispatch();
43 42
     const cancel = useCallback(() => dispatch(hideDialog()), [ dispatch ]);
44
-    const isStartingSilent = useSelector(getIsStartingSilent);
45
-    const participantsVolume = 1;
46
-    const initialParticipantsVolume = isStartingSilent ? undefined : participantsVolume;
47 43
     const displayName = p.name;
48 44
     const isLocalModerator = useSelector(isLocalParticipantModerator);
49 45
     const isParticipantVideoMuted = useSelector(getIsParticipantVideoMuted(p));
@@ -172,8 +168,7 @@ export const ContextMenuMeetingParticipantDetails = ({ participant: p }: Props)
172 168
             {/*    <Text style = { styles.contextMenuItemText }>{ t('participantsPane.actions.networkStats') }</Text>*/}
173 169
             {/* </TouchableOpacity>*/}
174 170
             <Divider style = { styles.divider } />
175
-            <VolumeSlider
176
-                initialValue = { initialParticipantsVolume } />
171
+            <VolumeSlider participant = { p } />
177 172
         </BottomSheet>
178 173
     );
179 174
 };

+ 14
- 2
react/features/participants-pane/reducer.js Просмотреть файл

@@ -2,12 +2,14 @@ import { ReducerRegistry } from '../base/redux';
2 2
 
3 3
 import {
4 4
     PARTICIPANTS_PANE_CLOSE,
5
-    PARTICIPANTS_PANE_OPEN
5
+    PARTICIPANTS_PANE_OPEN,
6
+    SET_VOLUME
6 7
 } from './actionTypes';
7 8
 import { REDUCER_KEY } from './constants';
8 9
 
9 10
 const DEFAULT_STATE = {
10
-    isOpen: false
11
+    isOpen: false,
12
+    participantsVolume: {}
11 13
 };
12 14
 
13 15
 /**
@@ -28,6 +30,16 @@ ReducerRegistry.register(
28 30
                 isOpen: true
29 31
             };
30 32
 
33
+        case SET_VOLUME:
34
+            return {
35
+                ...state,
36
+                participantsVolume: {
37
+                    ...state.participantsVolume,
38
+
39
+                    [action.participantId]: action.volume
40
+                }
41
+            };
42
+
31 43
         default:
32 44
             return state;
33 45
         }

+ 0
- 2
react/features/video-menu/components/AbstractBlockAudioVideoDialog.js Просмотреть файл

@@ -2,8 +2,6 @@
2 2
 
3 3
 import { Component } from 'react';
4 4
 
5
-import { blockParticipantsAudioVideo } from '../actions.any';
6
-
7 5
 type Props = {
8 6
 
9 7
     /**

+ 55
- 9
react/features/video-menu/components/native/VolumeSlider.js Просмотреть файл

@@ -6,7 +6,14 @@ import React, { PureComponent } from 'react';
6 6
 import { View } from 'react-native';
7 7
 import { withTheme } from 'react-native-paper';
8 8
 
9
+import { translate } from '../../../base/i18n';
9 10
 import { Icon, IconVolumeEmpty } from '../../../base/icons';
11
+import {
12
+    getLocalParticipant,
13
+    getParticipantById
14
+} from '../../../base/participants';
15
+import { connect } from '../../../base/redux';
16
+import { setVolume } from '../../../participants-pane/actions.native';
10 17
 import { VOLUME_SLIDER_SCALE } from '../../constants';
11 18
 
12 19
 /**
@@ -15,11 +22,24 @@ import { VOLUME_SLIDER_SCALE } from '../../constants';
15 22
 type Props = {
16 23
 
17 24
     /**
18
-     * The value of the audio slider should display at when the component first
19
-     * mounts. Changes will be stored in state. The value should be a number
20
-     * between 0 and 1.
25
+     * Whether the participant enters the conference silent.
21 26
      */
22
-    initialValue: number,
27
+    _startSilent: boolean,
28
+
29
+    /**
30
+     * The volume level for the participant.
31
+     */
32
+    _volume: number,
33
+
34
+    /**
35
+     * The redux dispatch function.
36
+     */
37
+    dispatch: Function,
38
+
39
+    /**
40
+     * Participant reference
41
+     */
42
+    participant: Object,
23 43
 
24 44
     /**
25 45
      * Theme used for styles.
@@ -58,7 +78,7 @@ class VolumeSlider extends PureComponent<Props, State> {
58 78
         super(props);
59 79
 
60 80
         this.state = {
61
-            volumeLevel: (props.initialValue || 0) * VOLUME_SLIDER_SCALE
81
+            volumeLevel: (props._volume || 0) * VOLUME_SLIDER_SCALE
62 82
         };
63 83
 
64 84
         this._originalVolumeChange = this._onVolumeChange;
@@ -75,9 +95,10 @@ class VolumeSlider extends PureComponent<Props, State> {
75 95
      * @returns {ReactElement}
76 96
      */
77 97
     render() {
78
-        const { theme } = this.props;
98
+        const { _startSilent, theme } = this.props;
79 99
         const { volumeLevel } = this.state;
80 100
         const { palette } = theme;
101
+        const onVolumeChange = _startSilent ? undefined : this._onVolumeChange;
81 102
 
82 103
         return (
83 104
             <View>
@@ -89,7 +110,7 @@ class VolumeSlider extends PureComponent<Props, State> {
89 110
                     maximumValue = { VOLUME_SLIDER_SCALE }
90 111
                     minimumTrackTintColor = { palette.action01 }
91 112
                     minimumValue = { 0 }
92
-                    onValueChange = { this._onVolumeChange }
113
+                    onValueChange = { onVolumeChange }
93 114
                     thumbTintColor = { palette.field02 }
94 115
                     value = { volumeLevel } />
95 116
             </View>
@@ -106,9 +127,34 @@ class VolumeSlider extends PureComponent<Props, State> {
106 127
      * @returns {void}
107 128
      */
108 129
     _onVolumeChange(volumeLevel) {
109
-        this.setState({ volumeLevel });
130
+        const { dispatch, participant } = this.props;
131
+        const { id } = participant;
132
+
133
+        dispatch(setVolume(id, volumeLevel));
110 134
     }
111 135
 }
112 136
 
113
-export default withTheme(VolumeSlider);
137
+/**
138
+ * Maps (parts of) the Redux state to the associated props for the
139
+ * {@code VolumeSlider} component.
140
+ *
141
+ * @param {Object} state - The Redux state.
142
+ * @param {Object} ownProps - The own props of the component.
143
+ * @returns {Props}
144
+ */
145
+function mapStateToProps(state, ownProps): Object {
146
+    const { participant } = ownProps;
147
+    const { startSilent } = state['features/base/config'];
148
+    const { participantsVolume } = state['features/participants-pane'];
149
+    const getParticipant = participant.id
150
+        ? getParticipantById(state, participant.id) : getLocalParticipant(state);
151
+    const { id } = getParticipant;
152
+
153
+    return {
154
+        _startSilent: Boolean(startSilent),
155
+        _volume: participant.local ? undefined : participantsVolume[id]
156
+    };
157
+}
158
+
159
+export default translate(connect(mapStateToProps)(withTheme(VolumeSlider)));
114 160
 

Загрузка…
Отмена
Сохранить