Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] 사용자 비디오 비율 개선 #186

Merged
merged 2 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import VoteResult from './GamePhases/VoteResult';
import EndingResult from './GamePhases/EndingResult';
import { usePeerConnectionStore } from '@/states/store/peerConnectionStore';
import VideoStream from '@/components/gamePage/stream/VideoStream';
import { useLocalStreamStore } from '@/states/store/localStreamStore';

export default function MainDisplay() {
const { userId } = useAuthStore();
Expand All @@ -34,8 +35,13 @@ export default function MainDisplay() {
setGamePhase,
setSelectedVote,
);
const remoteStreams = usePeerConnectionStore((state) => state.remoteStreams);
const currentStream = remoteStreams.get(currentSpeaker || '');
function getCurrentStream() {
const localStream = useLocalStreamStore.getState().localStream;
const remoteStreams = usePeerConnectionStore.getState().remoteStreams;
if (currentSpeaker === userId) return localStream;
const currentStream = remoteStreams.get(currentSpeaker || '');
return currentStream;
}

useEffect(() => {
if (gameStartData) {
Expand Down Expand Up @@ -85,9 +91,10 @@ export default function MainDisplay() {
<div className="flex flex-col items-center justify-center h-full">
<div className="w-4/6 p-4">
<VideoStream
stream={currentStream || null}
stream={getCurrentStream() || null}
userName={currentSpeaker}
isLocal={true}
height="h-full"
/>
</div>
<div className="absolute top-16 left-4 text-lg p-2 text-white-default bg-slate-950 rounded-lg">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,27 @@ export default function VideoFeed() {
const localStream = useLocalStreamStore((state) => state.localStream);
const remoteStreams = usePeerConnectionStore((state) => state.remoteStreams);
const { userId } = useAuthStore();
const feedHeight = 'h-[180px]';

return (
<>
<VideoStream stream={localStream} userName={userId} isLocal={true} />
<VideoStream stream={localStream} userName={userId} isLocal={true} height={feedHeight} />
{Array.from(remoteStreams).map(([userId, stream]) => (
<VideoStream key={userId} stream={stream} userName={userId} isLocal={false} />
<VideoStream
key={userId}
stream={stream}
userName={userId}
isLocal={false}
height={feedHeight}
/>
))}
{[...Array(Math.max(0, 5 - remoteStreams.size))].map((_, idx) => (
<VideoStream key={`empty-${idx}`} stream={null} userName={`빈 슬롯 ${idx + 1}`} />
<VideoStream
key={`empty-${idx}`}
stream={null}
userName={`빈 슬롯 ${idx + 1}`}
height={feedHeight}
/>
))}
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ interface IVideoStreamProps {
userName: string | null;
stream: MediaStream | null;
isLocal?: boolean;
height?: string;
}

export default function VideoStream({ userName, stream, isLocal }: IVideoStreamProps) {
export default function VideoStream({ userName, stream, isLocal, height }: IVideoStreamProps) {
const videoRef = useRef<HTMLVideoElement>(null);

useEffect(() => {
Expand All @@ -23,7 +24,9 @@ export default function VideoStream({ userName, stream, isLocal }: IVideoStreamP
}, [stream]);

return (
<div className="aspect-video relative w-full overflow-hidden bg-gray-700 rounded-lg min-h-32">
<div
className={`${height} aspect-video relative w-full overflow-hidden bg-gray-700 rounded-lg min-h-32`}
>
<video
ref={videoRef}
muted={isLocal}
Expand Down
1 change: 0 additions & 1 deletion packages/frontend/src/pages/gamePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export default function GamePage() {
return (
<>
<BackgroundImage gradientClass="bg-white/30" />
<Header />
<div className="relative flex w-full h-screen">
<LeftGameSection />
<RightGameSection />
Expand Down
Loading