Classroom Kick problemleri

This commit is contained in:
Sedat Öztürk 2025-08-31 22:00:48 +03:00
parent dfd05cbf57
commit b0566b7c6b
2 changed files with 21 additions and 5 deletions

View file

@ -29,6 +29,7 @@ export class SignalRService {
private onOfferReceived?: (fromUserId: string, offer: RTCSessionDescriptionInit) => void
private onAnswerReceived?: (fromUserId: string, answer: RTCSessionDescriptionInit) => void
private onIceCandidateReceived?: (fromUserId: string, candidate: RTCIceCandidateInit) => void
private onForceCleanup?: () => void
constructor() {
const { auth } = store.getState()
@ -109,19 +110,20 @@ export class SignalRService {
})
this.connection.onclose(async (err) => {
this.isConnected = false
// Eğer kick sebebiyle kapandıysa tekrar LeaveClass deneme
// 🚨 İlk satırda kontrol et
if (this.isKicked) {
this.isConnected = false
this.currentSessionId = undefined
return
}
this.isConnected = false
try {
if (this.currentSessionId) {
await this.connection.invoke('LeaveClass', this.currentSessionId)
}
} catch (err) {
} catch {
console.warn('LeaveClass could not be sent, connection was already closed')
} finally {
this.currentSessionId = undefined
@ -144,10 +146,15 @@ export class SignalRService {
console.warn('⚠️ ForceDisconnect received:', message)
this.isKicked = true
// 🔑 Cleanupu dışarıya delege et
if (this.onForceCleanup) {
this.onForceCleanup()
}
await this.connection.stop()
this.isConnected = false
// ✅ frontend stateden de çıkar
if (this.currentSessionId && store.getState().auth.user) {
this.onParticipantLeft?.({
userId: store.getState().auth.user.id,
@ -516,4 +523,8 @@ export class SignalRService {
getConnectionState(): boolean {
return this.isConnected
}
setForceCleanupHandler(callback: () => void) {
this.onForceCleanup = callback
}
}

View file

@ -353,6 +353,11 @@ const RoomDetail: React.FC = () => {
},
)
signalRServiceRef.current.setForceCleanupHandler(() => {
webRTCServiceRef.current?.closeAllConnections()
localStream?.getTracks().forEach((track) => track.stop())
})
signalRServiceRef.current.setParticipantLeaveHandler(({ userId, sessionId }) => {
console.log(`Participant left: ${userId} from session ${sessionId}`)