From b27a54eac4aab2d50b5b0790361d16583a31a3fb Mon Sep 17 00:00:00 2001 From: Jeremy Kahn Date: Mon, 7 Nov 2022 09:47:32 -0600 Subject: [PATCH] feat: improve peer video display --- src/components/Room/PeerVideo.tsx | 28 +++++++++++++++++++----- src/components/Room/RoomVideoDisplay.tsx | 16 +++++++++++--- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/components/Room/PeerVideo.tsx b/src/components/Room/PeerVideo.tsx index f6d9231..980642c 100644 --- a/src/components/Room/PeerVideo.tsx +++ b/src/components/Room/PeerVideo.tsx @@ -5,11 +5,24 @@ import { PeerNameDisplay } from 'components/PeerNameDisplay' interface PeerVideoProps { isSelf?: boolean + numberOfPeers: number userId: string videoStream: MediaStream } -export const PeerVideo = ({ isSelf, userId, videoStream }: PeerVideoProps) => { +// Adapted from https://www.geeksforgeeks.org/find-the-next-perfect-square-greater-than-a-given-number/ +const nextPerfectSquare = (base: number) => { + const nextInteger = Math.floor(Math.sqrt(base)) + 1 + + return nextInteger * nextInteger +} + +export const PeerVideo = ({ + isSelf, + numberOfPeers, + userId, + videoStream, +}: PeerVideoProps) => { const videoRef = useRef(null) useEffect(() => { @@ -20,15 +33,20 @@ export const PeerVideo = ({ isSelf, userId, videoStream }: PeerVideoProps) => { video.srcObject = videoStream }, [videoRef, videoStream]) + const sizePercent = 100 / Math.sqrt(nextPerfectSquare(numberOfPeers - 1)) + return ( diff --git a/src/components/Room/RoomVideoDisplay.tsx b/src/components/Room/RoomVideoDisplay.tsx index 1980dae..ebc77d0 100644 --- a/src/components/Room/RoomVideoDisplay.tsx +++ b/src/components/Room/RoomVideoDisplay.tsx @@ -35,27 +35,37 @@ export const RoomVideoDisplay = ({ userId }: RoomVideoDisplayProps) => { [] ) + const numberOfPeers = (selfVideoStream ? 1 : 0) + peersWithVideo.length + return ( {selfVideoStream && ( - + )} {peersWithVideo.map(peerWithVideo => (