fix(speaker-stats): get realtime local face expressions (#11334)

* fix(speaker-stats): get realtime local face expressions

* code review
This commit is contained in:
Gabriel Borlea 2022-04-07 13:02:43 +03:00 committed by GitHub
parent 6342e6b51a
commit 1fbbe7bc46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 13 deletions

View File

@ -1,11 +1,11 @@
// @flow
import { useCallback, useEffect } from 'react';
import { useCallback, useEffect, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
import { getLocalParticipant } from '../../base/participants';
import { initUpdateStats } from '../actions';
import { initUpdateStats } from '../actions.any';
import {
SPEAKER_STATS_RELOAD_INTERVAL
} from '../constants';
@ -26,8 +26,8 @@ const abstractSpeakerStatsList = (speakerStatsItem: Function, itemStyles?: Objec
const { defaultRemoteDisplayName } = useSelector(
state => state['features/base/config']) || {};
const { faceLandmarks } = useSelector(state => state['features/base/config']) || {};
const { faceExpressions: localFaceExpressions } = useSelector(
state => state['features/face-landmarks']) || {};
const { faceExpressions } = useSelector(state => state['features/face-landmarks']);
const reloadInterval = useRef(null);
/**
* Update the internal state with the latest speaker stats.
@ -35,7 +35,7 @@ const abstractSpeakerStatsList = (speakerStatsItem: Function, itemStyles?: Objec
* @returns {Object}
* @private
*/
const getLocalSpeakerStats = useCallback(() => {
const getSpeakerStats = useCallback(() => {
const stats = conference.getSpeakerStats();
for (const userId in stats) {
@ -49,7 +49,7 @@ const abstractSpeakerStatsList = (speakerStatsItem: Function, itemStyles?: Objec
: meString
);
if (faceLandmarks?.enableDisplayFaceExpressions) {
stats[userId].setFaceExpressions(localFaceExpressions);
stats[userId].setFaceExpressions(faceExpressions);
}
}
@ -62,21 +62,24 @@ const abstractSpeakerStatsList = (speakerStatsItem: Function, itemStyles?: Objec
}
return stats;
});
}, [ faceExpressions ]);
const updateStats = useCallback(
() => dispatch(initUpdateStats(getLocalSpeakerStats)),
[ dispatch, initUpdateStats ]);
() => dispatch(initUpdateStats(getSpeakerStats)),
[ dispatch, initUpdateStats, getSpeakerStats ]);
useEffect(() => {
const intervalId = setInterval(() => {
if (reloadInterval.current) {
clearInterval(reloadInterval.current);
}
reloadInterval.current = setInterval(() => {
updateStats();
}, SPEAKER_STATS_RELOAD_INTERVAL);
return () => clearInterval(intervalId);
}, []);
return () => clearInterval(reloadInterval.current);
}, [ faceExpressions ]);
const localSpeakerStats = Object.keys(speakerStats).length === 0 ? getLocalSpeakerStats() : speakerStats;
const localSpeakerStats = Object.keys(speakerStats).length === 0 ? getSpeakerStats() : speakerStats;
const userIds = Object.keys(localSpeakerStats).filter(id => localSpeakerStats[id] && !localSpeakerStats[id].hidden);
return userIds.map(userId => {