Don't request video for invisible group call participants

This commit is contained in:
Evan Hahn 2021-12-06 17:06:13 -06:00 committed by GitHub
parent b4b65c4f00
commit 01549b11d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 171 additions and 16 deletions

View file

@ -29,6 +29,7 @@ type BasePropsType = {
getFrameBuffer: () => ArrayBuffer;
getGroupCallVideoFrameSource: (demuxId: number) => VideoFrameSource;
i18n: LocalizerType;
onVisibilityChanged?: (demuxId: number, isVisible: boolean) => unknown;
remoteParticipant: GroupCallRemoteParticipantType;
};
@ -52,7 +53,12 @@ export type PropsType = BasePropsType &
export const GroupCallRemoteParticipant: React.FC<PropsType> = React.memo(
props => {
const { getFrameBuffer, getGroupCallVideoFrameSource, i18n } = props;
const {
getFrameBuffer,
getGroupCallVideoFrameSource,
i18n,
onVisibilityChanged,
} = props;
const {
acceptedMessageRequest,
@ -95,6 +101,10 @@ export const GroupCallRemoteParticipant: React.FC<PropsType> = React.memo(
? intersectionObserverEntry.isIntersecting
: true;
useEffect(() => {
onVisibilityChanged?.(demuxId, isVisible);
}, [demuxId, isVisible, onVisibilityChanged]);
const wantsToShowVideo = hasRemoteVideo && !isBlocked && isVisible;
const hasVideoToShow = wantsToShowVideo && hasReceivedVideoRecently;