From 8e8bca6c5afcbca44234f243696137b7fc078838 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sedat=20=C3=96zt=C3=BCrk?= Date: Sat, 30 Aug 2025 01:43:26 +0300 Subject: [PATCH] Classroom video --- ui/src/views/classroom/RoomDetail.tsx | 108 +++++++++++--------------- 1 file changed, 46 insertions(+), 62 deletions(-) diff --git a/ui/src/views/classroom/RoomDetail.tsx b/ui/src/views/classroom/RoomDetail.tsx index 172719c5..83f3f39a 100644 --- a/ui/src/views/classroom/RoomDetail.tsx +++ b/ui/src/views/classroom/RoomDetail.tsx @@ -264,74 +264,58 @@ const RoomDetail: React.FC = () => { await webRTCServiceRef.current?.addIceCandidate(fromUserId, candidate) }) - // Setup SignalR event handlers - signalRServiceRef.current.setParticipantJoinHandler( - async (userId: string, name: string, isTeacher: boolean) => { - if (userId === user.id) return + // ExistingParticipants handler + // 🔑 ExistingParticipants handler + signalRServiceRef.current.setExistingParticipantsHandler( + async (existing: { userId: string; userName: string; isTeacher: boolean }[]) => { + for (const participant of existing) { + if (participant.userId === user.id) continue - console.log(`Participant joined: ${name}, isTeacher: ${isTeacher}`) + console.log( + `Existing participant: ${participant.userName}, isTeacher: ${participant.isTeacher}`, + ) - if (webRTCServiceRef.current) { - await webRTCServiceRef.current.createPeerConnection(userId) + if (webRTCServiceRef.current) { + if (!webRTCServiceRef.current.getPeerConnection(participant.userId)) { + await webRTCServiceRef.current.createPeerConnection(participant.userId) + } - // 🔑 Eğer ben öğrenci isem, öğretmen geldiğinde ben offer göndermeliyim - if (user.role === 'student' && isTeacher) { - const offer = await webRTCServiceRef.current.createOffer(userId) - await signalRServiceRef.current?.sendOffer(classSession.id, userId, offer) + // 🔑 Eğer ben öğrenci isem, öğretmen için offer gönder + if (user.role === 'student' && participant.isTeacher) { + const offer = await webRTCServiceRef.current.createOffer(participant.userId) + await signalRServiceRef.current?.sendOffer( + classSession.id, + participant.userId, + offer, + ) + } + + // 🔑 Eğer ben öğretmensem, öğrenci için offer gönder + if (user.role === 'teacher' && !participant.isTeacher) { + const offer = await webRTCServiceRef.current.createOffer(participant.userId) + await signalRServiceRef.current?.sendOffer( + classSession.id, + participant.userId, + offer, + ) + } } - // 🔑 Eğer ben öğretmensem, öğrenci geldiğinde ben offer göndermeliyim - if (user.role === 'teacher' && !isTeacher) { - const offer = await webRTCServiceRef.current.createOffer(userId) - await signalRServiceRef.current?.sendOffer(classSession.id, userId, offer) - } + setParticipants((prev) => { + const exists = prev.find((p) => p.id === participant.userId) + if (exists) return prev + return [ + ...prev, + { + id: participant.userId, + name: participant.userName, + isTeacher: participant.isTeacher, + isAudioMuted: classSettings.autoMuteNewParticipants, + isVideoMuted: classSettings.defaultCameraState === 'off', + }, + ] + }) } - - setParticipants((prev) => { - const existing = prev.find((p) => p.id === userId) - if (existing) return prev - return [ - ...prev, - { - id: userId, - name, - isTeacher, // ✅ artık backend’den gelen değer - isAudioMuted: classSettings.autoMuteNewParticipants, - isVideoMuted: classSettings.defaultCameraState === 'off', - }, - ] - }) - }, - ) - - // Existing participants handler - signalRServiceRef.current.setParticipantJoinHandler( - async (userId: string, name: string, isTeacher: boolean) => { - if (userId === user.id) return - - console.log(`Participant joined: ${name}, isTeacher: ${isTeacher}`) - - if (webRTCServiceRef.current) { - // 👇 duplicate connection engelle - if (!webRTCServiceRef.current.getPeerConnection(userId)) { - await webRTCServiceRef.current.createPeerConnection(userId) - } - } - - setParticipants((prev) => { - const existing = prev.find((p) => p.id === userId) - if (existing) return prev - return [ - ...prev, - { - id: userId, - name, - isTeacher, - isAudioMuted: classSettings.autoMuteNewParticipants, - isVideoMuted: classSettings.defaultCameraState === 'off', - }, - ] - }) }, )