From 9254493e96eeaaad19ddcfb1dbd6d1588c298897 Mon Sep 17 00:00:00 2001 From: Oliver Lazoroski Date: Wed, 4 Oct 2023 14:20:04 +0200 Subject: [PATCH] fix: simplify screen share layout --- .../components/Participant/Participant.tsx | 15 ++- .../ParticipantsSlider/ParticipantsSlider.tsx | 17 ++- .../ScreenShareParticipants.tsx | 126 +++++++----------- 3 files changed, 65 insertions(+), 93 deletions(-) diff --git a/sample-apps/react/react-video-demo/src/components/Participant/Participant.tsx b/sample-apps/react/react-video-demo/src/components/Participant/Participant.tsx index d77eee4b10..35c59bdfc4 100644 --- a/sample-apps/react/react-video-demo/src/components/Participant/Participant.tsx +++ b/sample-apps/react/react-video-demo/src/components/Participant/Participant.tsx @@ -28,8 +28,8 @@ export type Props = { }; const VideoPlaceholder = forwardRef( - ({ participant }, ref) => ( -
+ ({ participant, style }, ref) => ( +
{(participant.name || participant.userId)?.split('')[0]} @@ -97,12 +97,12 @@ export const Overlay: FC<{ ); }; -export const Participant: FC = ({ +export const Participant = ({ className, call, participant, slider, -}) => { +}: Props) => { const { publishedTracks, isSpeaking, @@ -125,7 +125,10 @@ export const Participant: FC = ({ const isPinned = !!participant.pin; useEffect(() => { - if (connectionQuality === SfuModels.ConnectionQuality.POOR) { + if ( + isLocalParticipant && + connectionQuality === SfuModels.ConnectionQuality.POOR + ) { addNotification({ id: uuid(), message: @@ -133,7 +136,7 @@ export const Participant: FC = ({ icon: , }); } - }, [connectionQuality, addNotification]); + }, [connectionQuality, addNotification, isLocalParticipant]); const rootClassNames = classnames( styles.root, diff --git a/sample-apps/react/react-video-demo/src/components/ParticipantsSlider/ParticipantsSlider.tsx b/sample-apps/react/react-video-demo/src/components/ParticipantsSlider/ParticipantsSlider.tsx index 1bd94d1ade..57196f7b51 100644 --- a/sample-apps/react/react-video-demo/src/components/ParticipantsSlider/ParticipantsSlider.tsx +++ b/sample-apps/react/react-video-demo/src/components/ParticipantsSlider/ParticipantsSlider.tsx @@ -2,8 +2,11 @@ import { FC, useEffect, useState } from 'react'; import { FreeMode, Grid as GridModule, Mousewheel, Navigation } from 'swiper'; import { Swiper, SwiperSlide } from 'swiper/react'; import classnames from 'classnames'; -import { Call, StreamVideoParticipant } from '@stream-io/video-react-sdk'; -import { SfuModels } from '@stream-io/video-client'; +import { + Call, + SfuModels, + StreamVideoParticipant, +} from '@stream-io/video-react-sdk'; import { ChevronDown, ChevronLeft, ChevronRight, ChevronUp } from '../Icons'; import Participant from '../Participant'; @@ -80,7 +83,7 @@ export const ParticipantsSlider: FC = ({ } else { setMode(mode); } - }, [breakpoint]); + }, [breakpoint, mode]); const rootClassName = classnames( styles.root, @@ -133,7 +136,7 @@ export const ParticipantsSlider: FC = ({ }} className={swiperClassName} > - {participants?.map((participant, index) => { + {participants?.map((participant) => { const particpantHasVideo = participant.publishedTracks.includes( SfuModels.TrackType.VIDEO, ); @@ -144,9 +147,11 @@ export const ParticipantsSlider: FC = ({ }); return ( - + = ({ call }) => { undefined, ); - const { useLocalParticipant, useParticipants } = useCallStateHooks(); - const localParticipant = useLocalParticipant(); + const { useParticipants } = useCallStateHooks(); const allParticipants = useParticipants(); const firstScreenSharingParticipant = allParticipants.find((p) => p.publishedTracks.includes(SfuModels.TrackType.SCREEN_SHARE), ); - const wrapper: any = useRef(); + const [wrapper, setWrapper] = useState(null); useEffect(() => { - if (wrapper) { - const resizeObserver = new ResizeObserver((event) => { - if (!event[0]?.contentBoxSize) { - setWrapperHeight(event[0].contentRect.height); - } else { - setWrapperHeight(event[0].contentBoxSize[0].blockSize); - } - }); - - if (wrapper) { - resizeObserver.observe(wrapper.current); + if (!wrapper) return; + const resizeObserver = new ResizeObserver((event) => { + if (!event[0]?.contentBoxSize) { + setWrapperHeight(event[0].contentRect.height); + } else { + setWrapperHeight(event[0].contentBoxSize[0].blockSize); } + }); + if (wrapper) { + resizeObserver.observe(wrapper); } + return () => { + resizeObserver.unobserve(wrapper); + resizeObserver.disconnect(); + }; }, [wrapper]); const stopSharing = useCallback(async () => { await call.stopPublish(SfuModels.TrackType.SCREEN_SHARE); }, [call]); - if ( - firstScreenSharingParticipant?.sessionId === localParticipant?.sessionId - ) { - return ( -
- {wrapperHeight ? ( - <> - {firstScreenSharingParticipant ? ( -
-