Parcourir la source

feat: (speaker-stats) fix refresh and minor refactoring

factor2
Andrei Oltean il y a 4 ans
Parent
révision
8ef48a8a1d

+ 2
- 2
react/features/base/flags/constants.js Voir le fichier

@@ -99,10 +99,10 @@ export const IOS_SCREENSHARING_ENABLED = 'ios.screensharing.enabled';
99 99
 export const ANDROID_SCREENSHARING_ENABLED = 'android.screensharing.enabled';
100 100
 
101 101
 /**
102
- * Flag indicating if speaker statistics should be enabled in android.
102
+ * Flag indicating if speaker statistics should be enabled.
103 103
  * Default: enabled (true).
104 104
  */
105
-export const ANDROID_SPEAKERSTATS_ENABLED = 'android.speakerstats.enabled';
105
+export const SPEAKERSTATS_ENABLED = 'speakerstats.enabled';
106 106
 
107 107
 /**
108 108
  * Flag indicating if kickout is enabled.

+ 16
- 14
react/features/speaker-stats/components/AbstractSpeakerStatsList.js Voir le fichier

@@ -14,17 +14,17 @@ import {
14 14
  * Component that renders the list of speaker stats.
15 15
  *
16 16
  * @param {Function} speakerStatsItem - React element tu use when rendering.
17
- * @param {boolean} [isWeb=false] - Is for web in browser.
18 17
  * @returns {Function}
19 18
  */
20
-const abstractSpeakerStatsList = (speakerStatsItem: Function, isWeb: boolean = true): Function[] => {
19
+const abstractSpeakerStatsList = (speakerStatsItem: Function): Function[] => {
21 20
     const dispatch = useDispatch();
22 21
     const { t } = useTranslation();
23 22
     const conference = useSelector(state => state['features/base/conference'].conference);
23
+    const speakerStats = useSelector(state => state['features/speaker-stats'].stats);
24 24
     const localParticipant = useSelector(getLocalParticipant);
25
-    const { enableFacialRecognition } = isWeb ? useSelector(state => state['features/base/config']) : {};
26
-    const { facialExpressions: localFacialExpressions } = isWeb
27
-        ? useSelector(state => state['features/facial-recognition']) : {};
25
+    const { enableFacialRecognition } = useSelector(state => state['features/base/config']) || {};
26
+    const { facialExpressions: localFacialExpressions } = useSelector(
27
+        state => state['features/facial-recognition']) || {};
28 28
 
29 29
     /**
30 30
      * Update the internal state with the latest speaker stats.
@@ -62,21 +62,22 @@ const abstractSpeakerStatsList = (speakerStatsItem: Function, isWeb: boolean = t
62 62
     });
63 63
 
64 64
     const updateStats = useCallback(
65
-        () => dispatch(initUpdateStats(
66
-            () => getLocalSpeakerStats())), [ dispatch, initUpdateStats() ]);
65
+        () => dispatch(initUpdateStats(getLocalSpeakerStats)),
66
+        [ dispatch, initUpdateStats ]);
67 67
 
68 68
     useEffect(() => {
69
-        const updateInterval = setInterval(() => updateStats(), SPEAKER_STATS_RELOAD_INTERVAL);
69
+        const intervalId = setInterval(() => {
70
+            updateStats();
71
+        }, SPEAKER_STATS_RELOAD_INTERVAL);
70 72
 
71
-        return () => {
72
-            clearInterval(updateInterval);
73
-        };
74
-    }, [ dispatch, conference ]);
73
+        return () => clearInterval(intervalId);
74
+    }, []);
75 75
 
76
-    const userIds = Object.keys(getLocalSpeakerStats());
76
+    const localSpeakerStats = Object.keys(speakerStats).length === 0 ? getLocalSpeakerStats() : speakerStats;
77
+    const userIds = Object.keys(localSpeakerStats);
77 78
 
78 79
     return userIds.map(userId => {
79
-        const statsModel = getLocalSpeakerStats()[userId];
80
+        const statsModel = localSpeakerStats[userId];
80 81
 
81 82
         if (!statsModel || statsModel.hidden) {
82 83
             return null;
@@ -85,6 +86,7 @@ const abstractSpeakerStatsList = (speakerStatsItem: Function, isWeb: boolean = t
85 86
 
86 87
         props.isDominantSpeaker = statsModel.isDominantSpeaker();
87 88
         props.dominantSpeakerTime = statsModel.getTotalDominantSpeakerTime();
89
+        props.participantId = userId;
88 90
         props.hasLeft = statsModel.hasLeft();
89 91
         if (enableFacialRecognition) {
90 92
             props.facialExpressions = statsModel.getFacialExpressions();

+ 21
- 1
react/features/speaker-stats/components/native/SpeakerStatsButton.js Voir le fichier

@@ -1,6 +1,7 @@
1 1
 // @flow
2 2
 
3 3
 import { createToolbarEvent, sendAnalytics } from '../../../analytics';
4
+import { getFeatureFlag, SPEAKERSTATS_ENABLED } from '../../../base/flags';
4 5
 import { translate } from '../../../base/i18n';
5 6
 import { connect } from '../../../base/redux';
6 7
 import { navigate } from '../../../conference/components/native/ConferenceNavigationContainerRef';
@@ -25,4 +26,23 @@ class SpeakerStatsButton extends AbstractSpeakerStatsButton {
25 26
     }
26 27
 }
27 28
 
28
-export default translate(connect()(SpeakerStatsButton));
29
+/**
30
+ * Maps (parts of) the redux state to the associated props for the
31
+ * {@code SpeakerStatsButton} component.
32
+ *
33
+ * @param {Object} state - The Redux state.
34
+ * @private
35
+ * @returns {{
36
+ *     visible: boolean
37
+ * }}
38
+ */
39
+function _mapStateToProps(state): Object {
40
+    const enabled = getFeatureFlag(state, SPEAKERSTATS_ENABLED, true);
41
+
42
+    return {
43
+        visible: enabled
44
+    };
45
+}
46
+
47
+
48
+export default translate(connect(_mapStateToProps)(SpeakerStatsButton));

+ 6
- 1
react/features/speaker-stats/components/native/SpeakerStatsItem.js Voir le fichier

@@ -20,6 +20,11 @@ type Props = {
20 20
      */
21 21
     dominantSpeakerTime: number,
22 22
 
23
+    /**
24
+     * The id of the user.
25
+     */
26
+    participantId: string,
27
+
23 28
     /**
24 29
      * True if the participant is no longer in the meeting.
25 30
      */
@@ -41,7 +46,7 @@ const SpeakerStatsItem = (props: Props) => {
41 46
 
42 47
     return (
43 48
         <View
44
-            key = { props.displayName + props.dominantSpeakerTime }
49
+            key = { props.participantId }
45 50
             style = { style.speakerStatsItemContainer }>
46 51
             <View style = { style.speakerStatsItemStatus }>
47 52
                 <View style = { [ style.speakerStatsItemStatusDot, { backgroundColor: dotColor } ] } />

+ 1
- 1
react/features/speaker-stats/components/native/SpeakerStatsList.js Voir le fichier

@@ -13,7 +13,7 @@ import SpeakerStatsItem from './SpeakerStatsItem';
13 13
  * @returns {React$Element<any>}
14 14
  */
15 15
 const SpeakerStatsList = () => {
16
-    const items = abstractSpeakerStatsList(SpeakerStatsItem, false);
16
+    const items = abstractSpeakerStatsList(SpeakerStatsItem);
17 17
 
18 18
     return (
19 19
         <View>

+ 6
- 1
react/features/speaker-stats/components/web/SpeakerStatsItem.js Voir le fichier

@@ -35,6 +35,11 @@ type Props = {
35 35
      */
36 36
     dominantSpeakerTime: number,
37 37
 
38
+    /**
39
+     * The id of the user.
40
+     */
41
+    participantId: string,
42
+
38 43
     /**
39 44
      * True if the participant is no longer in the meeting.
40 45
      */
@@ -68,7 +73,7 @@ const SpeakerStatsItem = (props: Props) => {
68 73
     return (
69 74
         <div
70 75
             className = { rowDisplayClass }
71
-            key = { props.displayName } >
76
+            key = { props.participantId } >
72 77
             <div className = 'speaker-stats-item__status'>
73 78
                 <span className = { speakerStatusClass } />
74 79
             </div>

+ 0
- 2
react/features/speaker-stats/constants.js Voir le fichier

@@ -1,3 +1 @@
1 1
 export const SPEAKER_STATS_RELOAD_INTERVAL = 1000;
2
-
3
-export const SPEAKER_STATS_VIEW_MODEL_ID = 'speakerStats';

+ 2
- 1
react/features/toolbox/components/web/Toolbox.js Voir le fichier

@@ -10,7 +10,8 @@ import {
10 10
     createToolbarEvent,
11 11
     sendAnalytics
12 12
 } from '../../../analytics';
13
-import { getToolbarButtons, isToolbarButtonEnabled } from '../../../base/config';
13
+import { getToolbarButtons } from '../../../base/config';
14
+import { isToolbarButtonEnabled } from '../../../base/config/functions.web';
14 15
 import { openDialog, toggleDialog } from '../../../base/dialog';
15 16
 import { isIosMobileBrowser, isMobileBrowser } from '../../../base/environment/utils';
16 17
 import { translate } from '../../../base/i18n';

Chargement…
Annuler
Enregistrer