From f19a49b227d85e469b3b228ca60243ffba280d92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sedat=20=C3=96zt=C3=BCrk?= Date: Sat, 30 Aug 2025 12:53:28 +0300 Subject: [PATCH] =?UTF-8?q?Classroom=20Video=20d=C3=BCzenlemesi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/src/views/classroom/RoomDetail.tsx | 112 +++++++++++++------------- 1 file changed, 55 insertions(+), 57 deletions(-) diff --git a/ui/src/views/classroom/RoomDetail.tsx b/ui/src/views/classroom/RoomDetail.tsx index e11c6849..77aceb44 100644 --- a/ui/src/views/classroom/RoomDetail.tsx +++ b/ui/src/views/classroom/RoomDetail.tsx @@ -120,9 +120,6 @@ const RoomDetail: React.FC = () => { null, ) const [dragOver, setDragOver] = useState(false) - const [participantsActiveTab, setParticipantsActiveTab] = useState<'participants' | 'attendance'>( - 'participants', - ) const fileInputRef = useRef(null) const messagesEndRef = useRef(null) const [classSettings, setClassSettings] = useState({ @@ -272,82 +269,83 @@ const RoomDetail: React.FC = () => { console.log(`Participant joined: ${name}, isTeacher: ${isTeacher}`) - // Katılımcıyı state'e ekle setParticipants((prev) => { - if (prev.find((p) => p.id === userId)) return prev - return [ - ...prev, - { + const updated = [...prev] + if (!updated.find((p) => p.id === userId)) { + updated.push({ id: userId, name, isTeacher, isAudioMuted: classSettings.autoMuteNewParticipants, isVideoMuted: classSettings.defaultCameraState === 'off', - }, - ] + }) + } + + // ✅ güncel listedeki öğretmen kontrolü + const teacherExists = updated.some((p) => p.isTeacher) + if (teacherExists) { + ;(async () => { + if (!webRTCServiceRef.current?.getPeerConnection(userId)) { + await webRTCServiceRef.current?.createPeerConnection(userId) + } + if (user.id < userId) { + const offer = await webRTCServiceRef.current!.createOffer(userId) + await signalRServiceRef.current?.sendOffer(classSession.id, userId, offer) + } + })() + } else { + console.log('Teacher yok, offer başlatılmadı.') + } + + return updated }) - - // ✅ sadece öğretmen sınıfta ise offer başlasın - const teacherExists = hasTeacher(participants) || isTeacher - if (!teacherExists) { - console.log('Teacher yok, yeni join için offer başlatılmıyor.') - return - } - - if (!webRTCServiceRef.current?.getPeerConnection(userId)) { - await webRTCServiceRef.current?.createPeerConnection(userId) - } - - // Küçük id kuralı - if (user.id < userId) { - const offer = await webRTCServiceRef.current!.createOffer(userId) - await signalRServiceRef.current?.sendOffer(classSession.id, userId, offer) - } }, ) // 🔑 ExistingParticipants handler signalRServiceRef.current.setExistingParticipantsHandler( async (existing: { userId: string; userName: string; isTeacher: boolean }[]) => { - for (const participant of existing) { - if (participant.userId === user.id) continue + setParticipants((prev) => { + let updated = [...prev] - // Katılımcıyı state'e ekle - setParticipants((prev) => { - if (prev.find((p) => p.id === participant.userId)) return prev - return [ - ...prev, - { + for (const participant of existing) { + if (participant.userId === user.id) continue + if (!updated.find((p) => p.id === participant.userId)) { + updated.push({ id: participant.userId, name: participant.userName, isTeacher: participant.isTeacher, isAudioMuted: classSettings.autoMuteNewParticipants, isVideoMuted: classSettings.defaultCameraState === 'off', - }, - ] - }) - } - - // ✅ sadece öğretmen varsa offer başlat - const teacherExists = existing.some((p) => p.isTeacher) - if (!teacherExists) { - console.log('Teacher yok, offer başlatılmıyor.') - return - } - - for (const participant of existing) { - if (participant.userId === user.id) continue - - if (!webRTCServiceRef.current?.getPeerConnection(participant.userId)) { - await webRTCServiceRef.current?.createPeerConnection(participant.userId) + }) + } } - // Küçük id'li offer göndersin (çift offer olmaması için) - if (user.id < participant.userId) { - const offer = await webRTCServiceRef.current!.createOffer(participant.userId) - await signalRServiceRef.current?.sendOffer(classSession.id, participant.userId, offer) + // ✅ güncel listede öğretmen var mı? + const teacherExists = updated.some((p) => p.isTeacher) + if (teacherExists) { + ;(async () => { + for (const participant of existing) { + if (participant.userId === user.id) continue + if (!webRTCServiceRef.current?.getPeerConnection(participant.userId)) { + await webRTCServiceRef.current?.createPeerConnection(participant.userId) + } + if (user.id < participant.userId) { + const offer = await webRTCServiceRef.current!.createOffer(participant.userId) + await signalRServiceRef.current?.sendOffer( + classSession.id, + participant.userId, + offer, + ) + } + } + })() + } else { + console.log('Teacher yok, offer başlatılmadı (existing).') } - } + + return updated + }) }, )