-
Notifications
You must be signed in to change notification settings - Fork 4
[Refactor] 세션 페이지 컴포넌트 분리, 커스텀 훅 분리, UI 개선, 화상 회의 도중 미디어 장치 변경 가능하도록 수정 #63
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
Merged
ShipFriend0516
merged 18 commits into
boostcampwm-2024:dev
from
ShipFriend0516:refactor/session-page
Nov 11, 2024
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
4155b62
refactor: 소켓 연결 실패시 에러처리 핸들러 등록
ShipFriend0516 afd9ee2
refactor: useSocket로 소켓 초기화하는 코드 커스텀 hook으로 분리
ShipFriend0516 8c1b7bb
refactor: 세션 페이지의 사이드바 컴포넌트를 분리
ShipFriend0516 2c143f1
refactor: 세션 페이지의 Footer 툴바 컴포넌트를 분리
ShipFriend0516 bfc3ff1
feat: 공감 버튼 UI 구현
ShipFriend0516 71a2c7c
refactor: useSocket 매개변수에 따라 재실행되도록 수정
ShipFriend0516 08c36d7
feat: 질문 넘기기 버튼을 aria-label로 접근성 향상
ShipFriend0516 2707dee
refactor: useMediaDevices 훅으로 미디어 장치와 미디어 스트림 관리를 하나로 분리
ShipFriend0516 066c6cf
feat: 화상회의 도중 미디어 장치를 바꾸면 바로 스트림에 적용되도록 구현
ShipFriend0516 168fef0
fix: 방 참가를 안해도 미디어 장치가 켜지던 오류 해결
ShipFriend0516 b669619
feat: 발견된 미디어 장치가 없을 때 없다고 표시하도록 구현
ShipFriend0516 d43232a
style: 전체 레이아웃 최대 너비 증가 및 각 비디오 컴포넌트 최대크기 지정
ShipFriend0516 d2ae18e
style: toolbar 버튼 스타일 수정
ShipFriend0516 e9c8416
style: 미디어 장치 선택 select 너비 증가
ShipFriend0516 37e9547
style: pretendard font 추가 및 root font 설정
ShipFriend0516 93d433e
feat: 참가자 목록을 사이드바에서 볼 수 있도록 구현
ShipFriend0516 cd77996
refactor: 오류메시지 수정
ShipFriend0516 ee147b0
Merge branch 'dev' into refactor/session-page
ShipFriend0516 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
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains hidden or 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,50 @@ | ||
| import { FaClipboardList } from "react-icons/fa"; | ||
| import { FaUserGroup } from "react-icons/fa6"; | ||
|
|
||
| interface Props { | ||
| question: string; | ||
| participants: string[]; | ||
| } | ||
|
|
||
| const SessionSidebar = ({ question, participants }: Props) => { | ||
| return ( | ||
| <div className={"flex flex-col justify-between w-[440px] px-6"}> | ||
| <div className={"flex flex-col gap-4"}> | ||
| <div className={"flex flex-col gap-2"}> | ||
| <h2 className={"inline-flex gap-1 items-center text-semibold-s"}> | ||
| <FaClipboardList /> | ||
| 질문 | ||
| </h2> | ||
| <p | ||
| className={ | ||
| "border border-accent-gray p-2 bg-transparent rounded-xl" | ||
| } | ||
| > | ||
| {question} | ||
| </p> | ||
| </div> | ||
| <div className={"flex flex-col gap-2"}> | ||
| <h2 className={"inline-flex gap-1 items-center text-semibold-s"}> | ||
| <FaUserGroup /> | ||
| 참가자 | ||
| </h2> | ||
| <ul> | ||
| {participants.map((participant, index) => ( | ||
| <li key={index} className={"flex items-center gap-2"}> | ||
| <span className={"w-4 h-4 bg-accent-gray rounded-full"} /> | ||
| <span>{participant}</span> | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| </div> | ||
| </div> | ||
| <div className={"h-16 items-center flex w-full"}> | ||
| <button className={"w-full bg-red-500 text-white rounded-md py-2"}> | ||
| 종료하기 | ||
| </button> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default SessionSidebar; |
This file contains hidden or 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,106 @@ | ||
| import { FaAngleLeft, FaAngleRight } from "react-icons/fa6"; | ||
| import { | ||
| BsCameraVideo, | ||
| BsCameraVideoOff, | ||
| BsMic, | ||
| BsMicMute, | ||
| BsHandThumbsUp, | ||
| } from "react-icons/bs"; | ||
|
|
||
| interface Props { | ||
| handleVideoToggle: () => void; | ||
| handleMicToggle: () => void; | ||
| userVideoDevices: MediaDeviceInfo[]; | ||
| userAudioDevices: MediaDeviceInfo[]; | ||
| setSelectedVideoDeviceId: (deviceId: string) => void; | ||
| setSelectedAudioDeviceId: (deviceId: string) => void; | ||
| isVideoOn: boolean; | ||
| isMicOn: boolean; | ||
| } | ||
| const SessionToolbar = ({ | ||
| handleVideoToggle, | ||
| handleMicToggle, | ||
| userVideoDevices, | ||
| userAudioDevices, | ||
| setSelectedVideoDeviceId, | ||
| setSelectedAudioDeviceId, | ||
| isVideoOn, | ||
| isMicOn, | ||
| }: Props) => { | ||
| return ( | ||
| <div | ||
| className={ | ||
| "session-footer h-16 inline-flex w-full justify-between items-center border-t px-6" | ||
| } | ||
| > | ||
| <button | ||
| className={"bg-transparent rounded-full border p-3 text-xl"} | ||
| aria-label={"이전 질문 버튼"} | ||
| > | ||
| <FaAngleLeft /> | ||
| </button> | ||
| <div className={"inline-flex center-buttons gap-2"}> | ||
| <button | ||
| onClick={handleVideoToggle} | ||
| className="h-full aspect-square bg-green-500 hover:bg-green-600 text-white p-3 rounded-full" | ||
| aria-label={isVideoOn ? `비디오 끄기` : "비디오 켜기"} | ||
| > | ||
| {isVideoOn ? <BsCameraVideo /> : <BsCameraVideoOff />} | ||
| </button> | ||
| <button | ||
| onClick={handleMicToggle} | ||
| className="h-full aspect-square bg-green-500 hover:bg-green-600 text-white p-3 rounded-full" | ||
| aria-label={isMicOn ? `마이크 끄기` : "마이크 켜기"} | ||
| > | ||
| {isMicOn ? <BsMic /> : <BsMicMute />} | ||
| </button> | ||
| <button | ||
| className="h-full aspect-square bg-white text-green-500 border box-border border-accent-gray-50 hover:bg-grayscale-50 p-3 rounded-full" | ||
| aria-label={"좋아요"} | ||
| > | ||
| {<BsHandThumbsUp />} | ||
| </button> | ||
| <select | ||
| className={ | ||
| "max-w-40 bg-transparent text-gray-700 text-medium-xs border border-accent-gray py-2 px-2 rounded-xl hover:bg-gray-200" | ||
| } | ||
| onChange={(e) => setSelectedVideoDeviceId(e.target.value)} | ||
| > | ||
| {userVideoDevices.length > 0 ? ( | ||
| userVideoDevices.map((device) => ( | ||
| <option key={device.deviceId} value={device.deviceId}> | ||
| {device.label} | ||
| </option> | ||
| )) | ||
| ) : ( | ||
| <option value={""}>발견된 비디오 장치가 없습니다.</option> | ||
| )} | ||
| </select> | ||
| <select | ||
| className={ | ||
| "max-w-40 bg-transparent text-gray-700 text-medium-xs border border-accent-gray py-2 px-2 rounded-xl hover:bg-gray-200" | ||
| } | ||
| onChange={(e) => setSelectedAudioDeviceId(e.target.value)} | ||
| > | ||
| {userAudioDevices.length > 0 ? ( | ||
| userAudioDevices.map((device) => ( | ||
| <option key={device.deviceId} value={device.deviceId}> | ||
| {device.label} | ||
| </option> | ||
| )) | ||
| ) : ( | ||
| <option value={""}>발견된 오디오 장치가 없습니다.</option> | ||
| )} | ||
| </select> | ||
| </div> | ||
| <button | ||
| className={"bg-transparent rounded-full border p-3 text-xl"} | ||
| aria-label={"다음 질문 버튼"} | ||
| > | ||
| <FaAngleRight /> | ||
| </button> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default SessionToolbar; | ||
This file contains hidden or 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 hidden or 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,84 @@ | ||
| import { useEffect, useState } from "react"; | ||
|
|
||
| const useMediaDevices = () => { | ||
| // 유저의 미디어 장치 리스트 | ||
| const [userAudioDevices, setUserAudioDevices] = useState<MediaDeviceInfo[]>( | ||
| [] | ||
| ); | ||
| const [userVideoDevices, setUserVideoDevices] = useState<MediaDeviceInfo[]>( | ||
| [] | ||
| ); | ||
|
|
||
| // 유저가 선택한 미디어 장치 | ||
| const [selectedVideoDeviceId, setSelectedVideoDeviceId] = | ||
| useState<string>(""); | ||
| const [selectedAudioDeviceId, setSelectedAudioDeviceId] = | ||
| useState<string>(""); | ||
|
|
||
| // 본인 미디어 스트림 | ||
| const [stream, setStream] = useState<MediaStream | null>(null); | ||
|
|
||
| useEffect(() => { | ||
| // 비디오 디바이스 목록 가져오기 | ||
|
|
||
| const getUserDevices = async () => { | ||
| try { | ||
| const devices = await navigator.mediaDevices.enumerateDevices(); | ||
| const audioDevices = devices.filter( | ||
| (device) => device.kind === "audioinput" | ||
| ); | ||
| const videoDevices = devices.filter( | ||
| (device) => device.kind === "videoinput" | ||
| ); | ||
|
|
||
| setUserAudioDevices(audioDevices); | ||
| setUserVideoDevices(videoDevices); | ||
| } catch (error) { | ||
| console.error("미디어 기기를 찾는데 문제가 발생했습니다.", error); | ||
| } | ||
|
Comment on lines
+25
to
+38
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. try - catch 문 사용 너무 좋습니다! 문제가 발생했을 때 유저에게 어떤 변화를 줄 지도 추후에 생각해보는 식으로 확장해나가면 좋겠네요! |
||
| }; | ||
|
|
||
| getUserDevices(); | ||
| }, []); | ||
|
|
||
| // 미디어 스트림 가져오기: 자신의 스트림을 가져옴 | ||
| const getMedia = async () => { | ||
| try { | ||
| if (stream) { | ||
| // 이미 스트림이 있으면 종료 | ||
| stream.getTracks().forEach((track) => { | ||
| track.stop(); | ||
| }); | ||
| } | ||
| const myStream = await navigator.mediaDevices.getUserMedia({ | ||
| video: selectedVideoDeviceId | ||
| ? { deviceId: selectedVideoDeviceId } | ||
| : true, | ||
| audio: selectedAudioDeviceId | ||
| ? { deviceId: selectedAudioDeviceId } | ||
| : true, | ||
| }); | ||
|
|
||
| setStream(myStream); | ||
| return myStream; | ||
| } catch (error) { | ||
| console.error( | ||
| "미디어 스트림을 가져오는 도중 문제가 발생했습니다.", | ||
| error | ||
| ); | ||
| } | ||
| }; | ||
|
|
||
| return { | ||
| userAudioDevices, | ||
| userVideoDevices, | ||
| selectedAudioDeviceId, | ||
| selectedVideoDeviceId, | ||
| setSelectedAudioDeviceId, | ||
| setSelectedVideoDeviceId, | ||
| getMedia, | ||
| stream, | ||
| }; | ||
| }; | ||
|
|
||
| export default useMediaDevices; | ||
This file contains hidden or 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,28 @@ | ||
| import { useEffect, useState } from "react"; | ||
| import { Socket, io } from "socket.io-client"; | ||
|
|
||
| const useSocket = (socketURL: string) => { | ||
| // 소켓 상태 | ||
| const [socket, setSocket] = useState<Socket | null>(null); | ||
|
|
||
| // 소켓 연결 | ||
| useEffect(() => { | ||
| const newSocket = io(socketURL || "http://localhost:3000"); | ||
|
|
||
| newSocket.on("connect_error", socketErrorHandler); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 함수로 따로 빼주신 것 좋습니다! |
||
| setSocket(newSocket); | ||
|
|
||
| return () => { | ||
| newSocket.disconnect(); | ||
| setSocket(null); | ||
| }; | ||
| }, [socketURL]); | ||
|
|
||
| return { socket }; | ||
| }; | ||
|
|
||
| const socketErrorHandler = (error: Error) => { | ||
| console.error("시그널링 서버와의 연결에 실패했습니다.", error); | ||
| }; | ||
|
|
||
| export default useSocket; | ||
This file contains hidden or 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.
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.
인터페이스 구성 좋습니다!
제가 예엣날에 프론트 선배님(?)께 배운 방식은
컴포넌트Props로 별도로 명세해서 추가적으로 어떤 프로퍼티인지 알려주는 식으로 구성하긴 했어요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.
이 컴포넌트를 예시로 들 경우
SessionToolbarProps와 같은 형식이에용