-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat] ์ฌ์ฉ์๋ ๋ก๋น ํ์ด์ง์์ ๋ฏธ๋์ด ์ฅ์น๋ฅผ ๋ณ๊ฒฝํ ์ ์๋ค.
- Loading branch information
Showing
7 changed files
with
186 additions
and
2 deletions.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions
13
packages/frontend/src/components/gamePage/stream/MediaSourcePicker.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,13 @@ | ||
import DropBox from '@/components/lobbyPage/DropBox'; | ||
import { useLocalStreamStore } from '@/store/localStreamStore'; | ||
|
||
function MediaSourcePicker() { | ||
return ( | ||
<div className="flex flex-col gap-4 text-black left-0 w-full"> | ||
<DropBox title={'์นด๋ฉ๋ผ ์ค์ '} type="video" /> | ||
<DropBox title={'๋ง์ดํฌ ์ค์ '} type="audio" /> | ||
</div> | ||
); | ||
} | ||
|
||
export default MediaSourcePicker; |
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,87 @@ | ||
import { useState, useRef, useEffect } from 'react'; | ||
import ArrowDownIcon from '@/assets/images/DropBoxArrowDown.svg?react'; | ||
import ArrowUpIcon from '@/assets/images/DropBoxArrowUp.svg?react'; | ||
import { changeMediaDevice } from '@/utils/videoStreamUtils'; | ||
import { useLocalStreamStore } from '@/store/localStreamStore'; | ||
|
||
interface IDropBoxProps { | ||
title: string; | ||
type: 'video' | 'audio'; | ||
} | ||
|
||
function DropBox({ title, type }: IDropBoxProps) { | ||
const [isOpen, setIsOpen] = useState(false); | ||
const dropBoxRef = useRef<HTMLDivElement>(null); | ||
const videoDevices = useLocalStreamStore((state) => state.videoDevices); | ||
const audioInputDevices = useLocalStreamStore((state) => state.audioInputDevices); | ||
const currentVideoDevice = useLocalStreamStore((state) => state.currentVideoDevice); | ||
const currentAudioDevice = useLocalStreamStore((state) => state.currentAudioDevice); | ||
const targetMedia = type === 'video' ? currentVideoDevice : currentAudioDevice; | ||
const targetMediaList = type === 'video' ? videoDevices : audioInputDevices; | ||
const targetMediaLabel = targetMedia?.label || targetMediaList?.[0]?.label; | ||
|
||
function handleClick() { | ||
if (!targetMediaList?.length) return; | ||
setIsOpen(!isOpen); | ||
} | ||
|
||
function handleDeviceChange(device: MediaDeviceInfo) { | ||
if (device.kind === 'videoinput') { | ||
changeMediaDevice({ videoDeviceId: device.deviceId, audioDeviceId: '' }); | ||
} else { | ||
changeMediaDevice({ videoDeviceId: '', audioDeviceId: device.deviceId }); | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
function handleOutsideClick(event: MouseEvent) { | ||
if (dropBoxRef.current && !dropBoxRef.current.contains(event.target as Node)) { | ||
setIsOpen(false); | ||
} | ||
} | ||
|
||
document.addEventListener('mousedown', handleOutsideClick); | ||
return () => { | ||
document.removeEventListener('mousedown', handleOutsideClick); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<div | ||
ref={dropBoxRef} | ||
className="flex flex-col gap-2 cursor-pointer select-none" | ||
onClick={handleClick} | ||
> | ||
<span className="text-sm font-semibold">{title}</span> | ||
<div className="flex items-center gap-2 relative"> | ||
<div className="w-full border border-black rounded-lg px-4 py-2 flex items-center justify-between"> | ||
{targetMediaList?.length ? ( | ||
targetMediaLabel | ||
) : ( | ||
<span className="text-gray-500">์ฅ์น๊ฐ ์์ต๋๋ค</span> | ||
)} | ||
{isOpen ? <ArrowUpIcon /> : <ArrowDownIcon />} | ||
</div> | ||
{isOpen && ( | ||
<div className="border border-black rounded-lg p-2 absolute left-0 right-0 top-full mt-1 bg-white z-10"> | ||
{targetMediaList?.map((device) => { | ||
if (device.deviceId.includes('communications')) return null; | ||
return ( | ||
<div | ||
key={device.deviceId} | ||
className="p-2 hover:bg-gray-200 cursor-pointer rounded-lg flex items-center gap-2" | ||
onClick={() => handleDeviceChange(device)} | ||
> | ||
{targetMediaLabel === device.label && <span className="text-green-500">โ </span>} | ||
{device.label} | ||
</div> | ||
); | ||
})} | ||
</div> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default DropBox; |
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