From 29da0f2ea494f4790d337fa1b9b334873f3be0fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sedat=20=C3=96zt=C3=BCrk?= Date: Sat, 30 Aug 2025 01:38:32 +0300 Subject: [PATCH] =?UTF-8?q?Classroom=20Videoplayer=20k=C4=B1s=C4=B1mlar?= =?UTF-8?q?=C4=B1=20d=C3=BCzeltildi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/src/views/classroom/RoomDetail.tsx | 55 ++++++++++++--------------- 1 file changed, 24 insertions(+), 31 deletions(-) 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}`)