From 8ffc6f6439d43d1b3967f80dc205076fda8c5d4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sedat=20=C3=96zt=C3=BCrk?= Date: Sat, 30 Aug 2025 01:53:59 +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 | 63 ++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) diff --git a/ui/src/views/classroom/RoomDetail.tsx b/ui/src/views/classroom/RoomDetail.tsx index 83f3f39a..067f6a5a 100644 --- a/ui/src/views/classroom/RoomDetail.tsx +++ b/ui/src/views/classroom/RoomDetail.tsx @@ -264,7 +264,55 @@ const RoomDetail: React.FC = () => { await webRTCServiceRef.current?.addIceCandidate(fromUserId, candidate) }) - // ExistingParticipants 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) { + if (!webRTCServiceRef.current.getPeerConnection(userId)) { + await webRTCServiceRef.current.createPeerConnection(userId) + } + + // student → teacher + if (user.role === 'student' && isTeacher) { + const offer = await webRTCServiceRef.current.createOffer(userId) + await signalRServiceRef.current?.sendOffer(classSession.id, userId, offer) + } + + // teacher → student + if (user.role === 'teacher' && !isTeacher) { + const offer = await webRTCServiceRef.current.createOffer(userId) + await signalRServiceRef.current?.sendOffer(classSession.id, userId, offer) + } + + // teacher ↔ teacher + if (user.role === 'teacher' && isTeacher) { + if (user.id < userId) { + const offer = await webRTCServiceRef.current.createOffer(userId) + await signalRServiceRef.current?.sendOffer(classSession.id, userId, offer) + } + } + } + + setParticipants((prev) => { + const exists = prev.find((p) => p.id === userId) + if (exists) return prev + return [ + ...prev, + { + id: userId, + name, + isTeacher, + isAudioMuted: classSettings.autoMuteNewParticipants, + isVideoMuted: classSettings.defaultCameraState === 'off', + }, + ] + }) + }, + ) + // 🔑 ExistingParticipants handler signalRServiceRef.current.setExistingParticipantsHandler( async (existing: { userId: string; userName: string; isTeacher: boolean }[]) => { @@ -299,6 +347,19 @@ const RoomDetail: React.FC = () => { offer, ) } + + // 🔑 Öğretmen ↔ Öğretmen + if (user.role === 'teacher' && participant.isTeacher) { + // id’si küçük olan offer göndersin + if (user.id < participant.userId) { + const offer = await webRTCServiceRef.current.createOffer(participant.userId) + await signalRServiceRef.current?.sendOffer( + classSession.id, + participant.userId, + offer, + ) + } + } } setParticipants((prev) => {