Skip to content

Commit 948d021

Browse files
committed
FE: [feat] 웹소켓 baseURL 업데이트 #53
1 parent 4554504 commit 948d021

3 files changed

Lines changed: 27 additions & 10 deletions

File tree

src/frontend/eyesee-user/src/app/exam-room/page.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"use client";
22

3-
import React, { useEffect, useRef } from "react";
3+
import React, { useEffect, useRef, useState } from "react";
44
import { api } from "@/apis";
55
import NextButton from "@/components/common/NextButton";
66
import { useUserIdStore } from "@/store/useUserIdStore";
7+
import { useStore } from "@/store/useStore";
78

89
const RealTimeVideoPage = () => {
910
const { userId } = useUserIdStore();
@@ -15,10 +16,10 @@ const RealTimeVideoPage = () => {
1516
// WebSocket 연결 설정
1617
const setupWebSocket = () => {
1718
// TODO: 웹소캣 서버
19+
console.log(userId);
1820
const socket = new WebSocket(
19-
// "ws://43.201.224.93:8000/ws/1"
2021
// `${process.env.NEXT_PUBLIC_WEBSOCKET_KEY}/${userId}`
21-
`ws://43.201.224.93:8000/ws/${userId}`
22+
`wss://43.201.224.93.nip.io/ws/${userId}`
2223
);
2324
socket.onopen = () => {
2425
console.log("WebSocket 연결 성공");
@@ -48,7 +49,8 @@ const RealTimeVideoPage = () => {
4849
}
4950
};
5051

51-
// 시작 시점에 API 호출
52+
// 시작 시점에 API 호출 - 추후 추가 예정
53+
/*
5254
const callStartRecordingApi = async () => {
5355
// JSON 데이터 생성
5456
const examData = {
@@ -64,7 +66,7 @@ const RealTimeVideoPage = () => {
6466
console.error("시작 API 호출 실패:", error);
6567
}
6668
};
67-
69+
*/
6870
// Canvas를 사용해 비디오 프레임을 WebSocket으로 전송
6971
const captureAndSendFrame = () => {
7072
if (
@@ -99,7 +101,7 @@ const RealTimeVideoPage = () => {
99101
// 초기화 작업: WebSocket 연결, 비디오 스트리밍 시작, 시작 API 호출
100102
useEffect(() => {
101103
const initialize = async () => {
102-
await callStartRecordingApi(); // 시작 API 호출
104+
// await callStartRecordingApi(); // 시작 API 호출
103105
setupWebSocket();
104106
await startStreaming();
105107

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { useState, useEffect } from "react";
2+
3+
export const useStore = <T, F>(
4+
store: (callback: (state: T) => unknown) => unknown,
5+
callback: (state: T) => F
6+
) => {
7+
const result = store(callback) as F;
8+
const [data, setData] = useState<F>();
9+
10+
useEffect(() => {
11+
setData(result);
12+
}, [result]);
13+
14+
return data;
15+
};

src/frontend/eyesee-user/src/store/useUserIdStore.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { create } from "zustand";
22
import { persist } from "zustand/middleware";
33

44
type UserIdStore = {
5-
userId: number;
6-
setUserId: (userId: number) => void;
5+
userId: number | null;
6+
setUserId: (newUserId: number) => void;
77
};
88

99
export const useUserIdStore = create(
1010
persist<UserIdStore>(
1111
(set) => ({
12-
userId: 1,
13-
setUserId: (userId) => set({ userId }),
12+
userId: null,
13+
setUserId: (newUserId) => set({ userId: newUserId }),
1414
}),
1515
{
1616
name: "userId-storage", // localStorage에 저장될 키 이름

0 commit comments

Comments
 (0)