diff --git a/ui/src/views/classroom/RoomDetail.tsx b/ui/src/views/classroom/RoomDetail.tsx index ad801ff7..172719c5 100644 --- a/ui/src/views/classroom/RoomDetail.tsx +++ b/ui/src/views/classroom/RoomDetail.tsx @@ -305,42 +305,35 @@ const RoomDetail: React.FC = () => { ) // Existing participants handler - signalRServiceRef.current.setExistingParticipantsHandler(async (existing) => { - console.log('Existing participants:', existing) + signalRServiceRef.current.setParticipantJoinHandler( + async (userId: string, name: string, isTeacher: boolean) => { + if (userId === user.id) return - if (webRTCServiceRef.current) { - for (const p of existing) { - const id = p.userId || p.UserId - const name = p.userName || p.UserName - const isTeacher = p.isTeacher ?? p.IsTeacher + console.log(`Participant joined: ${name}, isTeacher: ${isTeacher}`) - await webRTCServiceRef.current.createPeerConnection(id) - - // öğrenci → öğretmen - if (user.role === 'student' && isTeacher) { - const offer = await webRTCServiceRef.current.createOffer(id) - await signalRServiceRef.current?.sendOffer(classSession.id, id, offer) - } - - // öğretmen → öğrenci - if (user.role === 'teacher' && !isTeacher) { - const offer = await webRTCServiceRef.current.createOffer(id) - await signalRServiceRef.current?.sendOffer(classSession.id, id, offer) + if (webRTCServiceRef.current) { + // 👇 duplicate connection engelle + if (!webRTCServiceRef.current.getPeerConnection(userId)) { + await webRTCServiceRef.current.createPeerConnection(userId) } } - } - setParticipants((prev) => [ - ...prev, - ...existing.map((p) => ({ - id: p.userId || p.UserId, - name: p.userName || p.UserName, - isTeacher: p.isTeacher ?? p.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, + isAudioMuted: classSettings.autoMuteNewParticipants, + isVideoMuted: classSettings.defaultCameraState === 'off', + }, + ] + }) + }, + ) signalRServiceRef.current.setParticipantLeaveHandler((userId) => { console.log(`Participant left: ${userId}`)