Skip to content

Commit

Permalink
fix: select callType logic single or group #23
Browse files Browse the repository at this point in the history
  • Loading branch information
luckylooky2 committed Sep 25, 2023
1 parent 7f0447b commit 9475d4a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/components/Call/TopicButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import WaitToast from "@components/Call/WaitToast";
import { SocketContext } from "@contexts/SocketProvider";
import { CallContext } from "@contexts/CallProvider";
import { AuthContext } from "@contexts/AuthProvider";
import { COUNT, MILLISECOND, SINGLE_CALL } from "@utils/constant";
import { COUNT, MILLISECOND, SINGLE_CALL, GROUP_CALL } from "@utils/constant";

interface Props {
text: string;
Expand All @@ -17,6 +17,8 @@ const TopicButton: FC<Props> = ({ text, img, setVoteId }) => {
const { socket } = useContext(SocketContext);
const { callInfo } = useContext(CallContext);
const { myInfo } = useContext(AuthContext);
const callType =
callInfo.roomType === SINGLE_CALL.TYPE ? SINGLE_CALL : GROUP_CALL;

const chooseContents = useCallback(() => {
socket?.emit(
Expand All @@ -29,7 +31,7 @@ const TopicButton: FC<Props> = ({ text, img, setVoteId }) => {
},
(result: boolean) => {
if (result) {
const id = toast.info(<WaitToast callType={SINGLE_CALL} />, {
const id = toast.info(<WaitToast callType={callType} />, {
autoClose: (COUNT.VOTE - COUNT.DIFF) * MILLISECOND,
});
setVoteId(id);
Expand Down
24 changes: 15 additions & 9 deletions src/pages/Call.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ const Call = () => {
const [contents, setContents] = useState<any>([]);
const { callInfo, dispatch } = useContext(CallContext);
const { socket } = useContext(SocketContext);
const videos = new Array(callInfo.opponent?.length).fill(
useRef<HTMLVideoElement>(null)
);
const videos = [
useRef<HTMLVideoElement>(null),
useRef<HTMLVideoElement>(null),
useRef<HTMLVideoElement>(null),
];
const timeoutId = useRef<any>(0);
const peerRef = useRef<Peer.Instance[]>([]);
const peer = peerRef.current;
const totalNum =
callInfo.roomType === SINGLE_CALL.TYPE
? SINGLE_CALL.TOTAL_NUM - 1
: GROUP_CALL.TOTAL_NUM - 2;
: GROUP_CALL.TOTAL_NUM - 1;
const callType =
callInfo.roomType === SINGLE_CALL.TYPE ? SINGLE_CALL : GROUP_CALL;

// /call로 접근하였을 때 잘 login 화면으로 가는지?
useEffect(() => {
Expand Down Expand Up @@ -69,7 +73,7 @@ const Call = () => {
});

peer[i].on("stream", (currentStream) => {
videos[i].current.srcObject = currentStream;
videos[i].current!.srcObject = currentStream;
});

peer[i].on("error", (err) => {
Expand Down Expand Up @@ -186,7 +190,7 @@ const Call = () => {
<VoteToast
contentsName={data.contentsName}
requester={data.requester}
callType={SINGLE_CALL}
callType={callType}
/>,
{ autoClose: (COUNT.VOTE - COUNT.DIFF) * MILLISECOND }
);
Expand All @@ -204,9 +208,10 @@ const Call = () => {
autoClose: COUNT.DEFAULT * MILLISECOND,
isLoading: false,
});
// 컨텐츠 업데이트
setContents(data.contents);
setScreen(SCREEN.TOPIC_MODAL);
if (data.result) {
setContents(data.contents);
setScreen(SCREEN.TOPIC_MODAL);
}
},
[voteId]
);
Expand All @@ -220,6 +225,7 @@ const Call = () => {
<div className="h-[15%] flex flex-col justify-evenly">
{callInfo.opponent?.map((v, i) => (
<video
key={`opponentVideo-${v}-${i}`}
width={1}
height={1}
playsInline
Expand Down

0 comments on commit 9475d4a

Please sign in to comment.