-
Notifications
You must be signed in to change notification settings - Fork 2
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] 설정 다이얼로그를 통한 마이크/카메라 선택 기능 구현 #338
Merged
+517
−99
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a5e54a7
feat: 미디어 스트림 설정을 위한 기본 제약 조건 추가 및 옵션 지원
seoko97 12af3aa
feat: 미디어 장치 관리 기능 추가 및 선택된 장치 ID 설정 로직 구현
seoko97 f50466b
feat: 설정 아이콘 SVG 파일 추가
seoko97 55bba7a
feat: 미디어 장치의 deviceId 속성을 value로 변경
seoko97 15992af
feat: position 순서 정렬을 통한 z index 제거
seoko97 c2d6062
feat: 설정 다이얼로그 추가 및 제어바에 설정 아이콘 토글 버튼 구현
seoko97 60a7eaa
feat: useEffect 의존성 배열에서 불필요한 stream 제거
seoko97 94296a0
feat: 설정 다이얼로그에 오디오 및 비디오 선택 기능 추가
seoko97 13d7a72
feat: 미디어 장치 필터링에서 기본 deviceId 제외
seoko97 9e03d57
feat: 선택 가능한 카메라 및 마이크가 없을 때 사용자에게 메시지 표시
seoko97 e159270
fix: 병합 충돌 해결
seoko97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
apps/web/src/components/live/SettingDialog/SelectMedia.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { useEffect, useRef, useState } from 'react'; | ||
|
||
import { useLocalStreamAction, useLocalStreamState } from '@/contexts/localStream/context'; | ||
import { getCameraStream } from '@/utils/stream'; | ||
|
||
function SelectMedia() { | ||
const videoRef = useRef<HTMLVideoElement>(null); | ||
const [stream, setStream] = useState<MediaStream | null>(null); | ||
|
||
const { videoDevices, audioDevices, selectedVideoDeviceId, selectedAudioDeviceId } = | ||
useLocalStreamState(); | ||
|
||
const { setSelectedVideoDeviceId, setSelectedAudioDeviceId } = useLocalStreamAction(); | ||
|
||
useEffect(() => { | ||
const getStream = async () => { | ||
if (!selectedVideoDeviceId || !videoRef.current) return; | ||
|
||
stream?.getTracks().forEach((track) => track.stop()); | ||
|
||
const cameraStream = await getCameraStream({ video: { deviceId: selectedVideoDeviceId } }); | ||
|
||
videoRef.current.srcObject = cameraStream; | ||
|
||
setStream(cameraStream); | ||
}; | ||
|
||
getStream(); | ||
}, [selectedVideoDeviceId]); | ||
|
||
return ( | ||
<div className="flex h-full flex-col gap-y-4 overflow-y-auto"> | ||
<div> | ||
<h2 className="text-h4 text-alt">카메라</h2> | ||
<video | ||
ref={videoRef} | ||
autoPlay | ||
playsInline | ||
className="aspect-video w-full rounded-lg bg-alt" | ||
/> | ||
{videoDevices.length === 0 && ( | ||
<p className="mt-2 text-body2 text-alt">사용 가능한 카메라가 없습니다.</p> | ||
)} | ||
{videoDevices.length !== 0 && ( | ||
<select | ||
value={selectedVideoDeviceId ?? '선택'} | ||
onChange={(e) => setSelectedVideoDeviceId(e.target.value)} | ||
className="mt-2 w-full" | ||
> | ||
{videoDevices.map((device) => ( | ||
<option key={device.value} value={device.value}> | ||
{device.label} | ||
</option> | ||
))} | ||
</select> | ||
)} | ||
</div> | ||
<div> | ||
<h2 className="text-h4 text-alt">마이크</h2> | ||
{audioDevices.length === 0 && ( | ||
<p className="mt-2 text-body2 text-alt">사용 가능한 마이크가 없습니다.</p> | ||
)} | ||
{audioDevices.length !== 0 && ( | ||
<select | ||
disabled={audioDevices.length === 0} | ||
value={selectedAudioDeviceId ?? '선택'} | ||
className="mt-2 w-full" | ||
onChange={(e) => setSelectedAudioDeviceId(e.target.value)} | ||
> | ||
{audioDevices.map((device) => ( | ||
<option key={device.value} value={device.value}> | ||
{device.label} | ||
</option> | ||
))} | ||
</select> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default SelectMedia; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { cva } from 'class-variance-authority'; | ||
import { useState } from 'react'; | ||
|
||
import { Dialog } from '@/components/common/Dialog'; | ||
import SelectMedia from '@/components/live/SettingDialog/SelectMedia'; | ||
|
||
const listVariants = cva( | ||
'flex w-full cursor-pointer items-center justify-center rounded-md px-4 py-2 text-sm', | ||
{ | ||
variants: { | ||
active: { | ||
false: 'text-body1 hover:bg-alt', | ||
true: 'bg-primary text-white', | ||
}, | ||
}, | ||
defaultVariants: { | ||
active: false, | ||
}, | ||
} | ||
); | ||
|
||
const SIDEBAR_ITEMS = [ | ||
{ | ||
title: '오디오 및 비디오', | ||
Component: SelectMedia, | ||
}, | ||
] as const; | ||
|
||
interface SettingDialogProps { | ||
isOpen: boolean; | ||
onClose: () => void; | ||
} | ||
|
||
function SettingDialog({ isOpen, onClose }: SettingDialogProps) { | ||
const [activeIndex, setActiveIndex] = useState(0); | ||
|
||
const Component = SIDEBAR_ITEMS[activeIndex]?.Component; | ||
|
||
return ( | ||
<Dialog.Root isOpen={isOpen} onClose={onClose} className="flex h-[500px] w-[600px] flex-col"> | ||
<Dialog.Title>Settings</Dialog.Title> | ||
<Dialog.Close onClose={onClose} /> | ||
<Dialog.Content className="flex h-full flex-1 items-center justify-center gap-x-4"> | ||
<ul className="flex h-full basis-32 flex-col items-start justify-start gap-y-2"> | ||
{SIDEBAR_ITEMS.map((item, index) => ( | ||
<li | ||
key={index} | ||
className={listVariants({ active: activeIndex === index })} | ||
onClick={() => setActiveIndex(index)} | ||
> | ||
{item.title} | ||
</li> | ||
))} | ||
</ul> | ||
<div className="h-full flex-1">{Component && <Component />}</div> | ||
</Dialog.Content> | ||
</Dialog.Root> | ||
); | ||
} | ||
export default SettingDialog; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P4
기왕 하는거 Select 공통 컴포넌트를 사용하면 좋을거같긴합니다~! 우선순위는 매우 낮으니 이 부분은 제가 수정할게요!!