-
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.
- Loading branch information
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/frontend/apps/web/src/features/video/api/get-huddle-status.api.ts
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,11 @@ | ||
'use server'; | ||
|
||
import { serverFetchInstance } from '@/src/shared/services'; | ||
|
||
export const getHuddleStatus = async (channeld: any) => { | ||
try { | ||
const staus = serverFetchInstance(`/api/v1/huddle/${channeld}`, 'GET'); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}; |
68 changes: 68 additions & 0 deletions
68
src/frontend/apps/web/src/features/video/model/use-websocket-huddle.ts
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,68 @@ | ||
'use client'; | ||
import { useRef, useState } from 'react'; | ||
import * as StompJs from '@stomp/stompjs'; | ||
import SockJS from 'sockjs-client'; | ||
|
||
const STOMP_SERVER_URL = `${process.env.NEXT_PUBLIC_STOMP_SERVER}`; | ||
const STOMP_PATH = { | ||
PUB_URL: `${process.env.NEXT_PUBLIC_PUB_URL}`, | ||
SUB_URL: `${process.env.NEXT_PUBLIC_SUB_URL}`, | ||
PRIVATE_SUB_URL: `${process.env.NEXT_PUBLIC_PRIVATE_SUB_URL}`, | ||
}; | ||
|
||
export const useWebsocketHuddle = ({ | ||
userId, | ||
channelId, | ||
}: { | ||
userId: number; | ||
channelId: number; | ||
}) => { | ||
const stompClient = useRef<StompJs.Client | null>(null); | ||
const [isConnected, setIsConnected] = useState(false); | ||
const [messages, setMessages] = useState<string[]>([]); | ||
|
||
stompClient.current = new StompJs.Client({ | ||
connectHeaders: { | ||
sessionId: userId.toString(), | ||
}, | ||
webSocketFactory: () => new SockJS(`${STOMP_SERVER_URL}`), | ||
onConnect: () => { | ||
console.log('허들 WebSocket Connected'); | ||
setIsConnected(true); | ||
console.log('start sub'); | ||
stompClient.current?.subscribe( | ||
`${STOMP_PATH.PRIVATE_SUB_URL}/${userId}`, | ||
handlePrivateMessage, | ||
); | ||
}, | ||
onStompError: (frame) => { | ||
console.error( | ||
'❌ WebSocket error:', | ||
frame.headers['message'], | ||
frame.body, | ||
); | ||
}, | ||
reconnectDelay: 0, | ||
}); | ||
|
||
stompClient.current.activate(); | ||
|
||
const handlePrivateMessage = () => {}; | ||
|
||
const sendMessage = (message: string) => { | ||
if (stompClient.current && stompClient) { | ||
stompClient.current.publish({ | ||
destination: '/app/chat', | ||
body: JSON.stringify({ userId, message }), | ||
}); | ||
} | ||
}; | ||
|
||
return () => { | ||
if (stompClient.current) { | ||
stompClient.current.deactivate(); | ||
stompClient.current = null; | ||
setIsConnected(false); | ||
} | ||
}; | ||
}; |