-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: 환경 변수 설정 * feat: SSE 연동해서 rooms 데이터 가져오기 초기 데이터는 GET 요청 보내서 처리 * docs: README.md 업데이트
- Loading branch information
1 parent
083c5a5
commit 466a4ac
Showing
13 changed files
with
96 additions
and
83 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ node_modules | |
dist | ||
dist-ssr | ||
*.local | ||
.env | ||
|
||
# Editor directories and files | ||
.vscode/* | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export const ENV = { | ||
GAME_SERVER_URL: import.meta.env.VITE_GAME_SERVER_URL, | ||
SIGNALING_SERVER_URL: import.meta.env.VITE_SIGNALING_SERVER_URL, | ||
STUN_SERVERS: { | ||
iceServers: [ | ||
{ | ||
urls: import.meta.env.VITE_STUN_SERVER, | ||
}, | ||
{ | ||
urls: import.meta.env.VITE_TURN_SERVER, | ||
username: import.meta.env.VITE_TURN_USERNAME, | ||
credential: import.meta.env.VITE_TURN_CREDENTIAL, | ||
}, | ||
], | ||
}, | ||
SSE_URL: import.meta.env.VITE_GAME_SSE_URL, | ||
REST_BASE_URL: import.meta.env.VITE_GAME_REST_BASE_URL, | ||
}; |
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 was deleted.
Oops, something went wrong.
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,49 @@ | ||
import useRoomStore from '@/stores/zustand/useRoomStore'; | ||
import { useEffect } from 'react'; | ||
import { Room } from '@/types/roomTypes'; | ||
import { ENV } from '@/config/env'; | ||
import { getRoomsQuery } from '@/stores/queries/getRoomsQuery'; | ||
|
||
export const useRoomsSSE = () => { | ||
const { data: initialRooms } = getRoomsQuery(); | ||
const { setRooms } = useRoomStore(); | ||
|
||
console.log(initialRooms); | ||
|
||
useEffect(() => { | ||
// 초기 데이터 설정 | ||
if (initialRooms) { | ||
setRooms(initialRooms); | ||
} | ||
|
||
// SSE 연결 | ||
const eventSource = new EventSource(ENV.SSE_URL); | ||
|
||
// rooms 데이터 수신 처리 | ||
eventSource.onmessage = (event) => { | ||
try { | ||
const rooms = JSON.parse(event.data) as Room[]; | ||
setRooms(rooms); | ||
} catch (error) { | ||
console.error('Failed to parse rooms data:', error); | ||
} | ||
}; | ||
|
||
// 연결 시작 | ||
eventSource.onopen = () => { | ||
console.log('SSE Connection opened'); | ||
}; | ||
|
||
// 에러 처리 | ||
eventSource.onerror = (error) => { | ||
console.error('SSE Error:', error); | ||
eventSource.close(); | ||
}; | ||
|
||
// 컴포넌트 언마운트 시 연결 정리 (메모리 누수 예방) | ||
return () => { | ||
console.log('Closing SSE connection'); | ||
eventSource.close(); | ||
}; | ||
}, [initialRooms, setRooms]); | ||
}; |
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
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