Classroom video

This commit is contained in:
Sedat Öztürk 2025-08-30 01:43:26 +03:00
parent 29da0f2ea4
commit 8e8bca6c5a

View file

@ -264,74 +264,58 @@ const RoomDetail: React.FC = () => {
await webRTCServiceRef.current?.addIceCandidate(fromUserId, candidate) await webRTCServiceRef.current?.addIceCandidate(fromUserId, candidate)
}) })
// Setup SignalR event handlers // ExistingParticipants handler
signalRServiceRef.current.setParticipantJoinHandler( // 🔑 ExistingParticipants handler
async (userId: string, name: string, isTeacher: boolean) => { signalRServiceRef.current.setExistingParticipantsHandler(
if (userId === user.id) return 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) { if (webRTCServiceRef.current) {
await webRTCServiceRef.current.createPeerConnection(userId) if (!webRTCServiceRef.current.getPeerConnection(participant.userId)) {
await webRTCServiceRef.current.createPeerConnection(participant.userId)
}
// 🔑 Eğer ben öğrenci isem, öğretmen geldiğinde ben offer göndermeliyim // 🔑 Eğer ben öğrenci isem, öğretmen için offer gönder
if (user.role === 'student' && isTeacher) { if (user.role === 'student' && participant.isTeacher) {
const offer = await webRTCServiceRef.current.createOffer(userId) const offer = await webRTCServiceRef.current.createOffer(participant.userId)
await signalRServiceRef.current?.sendOffer(classSession.id, userId, offer) 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 setParticipants((prev) => {
if (user.role === 'teacher' && !isTeacher) { const exists = prev.find((p) => p.id === participant.userId)
const offer = await webRTCServiceRef.current.createOffer(userId) if (exists) return prev
await signalRServiceRef.current?.sendOffer(classSession.id, userId, offer) 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 backendden 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',
},
]
})
}, },
) )