Skip to content

Commit

Permalink
🐛 fix: WebSocket再接続ロジックおよび状態管理の改善
Browse files Browse the repository at this point in the history
  • Loading branch information
yuminn-k committed Nov 24, 2024
1 parent 420997e commit 6386a17
Showing 1 changed file with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ const LiveClass: React.FC<LiveClassProps> = ({
const socket = io(window.location.origin, {
path: '/mediasoup',
transports: ['websocket'],
upgrade: false,
query: {
roomId: classId.toString(),
userId: userId.toString(),
Expand All @@ -248,15 +247,10 @@ const LiveClass: React.FC<LiveClassProps> = ({
reconnection: true,
reconnectionAttempts: 5,
reconnectionDelay: 1000,
timeout: 10000,
timeout: 20000,
forceNew: true,
autoConnect: false,
});

// 연결 상태 모니터링 강화
socket.on('connect', () => {
console.log('Socket connected:', socket.id);
setConnectionState('connected');
withCredentials: true,
});

socket.on('connect_error', (error: SocketIOError) => {
Expand All @@ -266,20 +260,19 @@ const LiveClass: React.FC<LiveClassProps> = ({
...(error.context && {context: error.context}),
...(error.type && {type: error.type}),
stack: error.stack,
url: window.location.origin,
path: '/mediasoup',
});
setConnectionState('disconnected');
});

socket.on('disconnect', reason => {
console.log('Socket disconnected:', reason);
setConnectionState('disconnected');
});

socket.connect();
socketRef.current = socket;

return () => {
socket.close();
if (socket.connected) {
socket.disconnect();
}
};
}, [classId, userId, nickname]);

Expand Down

0 comments on commit 6386a17

Please sign in to comment.