Skip to content

Commit

Permalink
✨ feat: 주식 메인페이지에서 웹소켓이 연결되고 있는 문제 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
baegyeong committed Dec 4, 2024
1 parent 513c91b commit e227459
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/frontend/src/sockets/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ export const socketChat = ({ stockId, pageSize = 20 }: SocketChatType) => {
pageSize,
},
forceNew: true,
autoConnect: false,
});
};

export const socketStock = io(`${URL}/api/stock/realtime`, {
transports: ['websocket'],
reconnectionDelayMax: 10000,
autoConnect: false,
});
5 changes: 5 additions & 0 deletions packages/frontend/src/sockets/useWebsocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export const useWebsocket = (socket: Socket) => {
const [isConnected, setIsConnected] = useState(socket.connected);

useEffect(() => {
if (!socket.connected) {
socket.connect();
}

const onConnect = () => {
setIsConnected(true);
};
Expand All @@ -19,6 +23,7 @@ export const useWebsocket = (socket: Socket) => {
return () => {
socket.off('connect', onConnect);
socket.off('disconnect', onDisconnect);
socket.disconnect();
};
}, [socket]);

Expand Down

0 comments on commit e227459

Please sign in to comment.