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 => (