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) {
await webRTCServiceRef.current.createPeerConnection(userId)
// 🔑 Eğer ben öğrenci isem, öğretmen geldiğinde ben offer göndermeliyim
if (user.role === 'student' && isTeacher) {
const offer = await webRTCServiceRef.current.createOffer(userId)
await signalRServiceRef.current?.sendOffer(classSession.id, userId, offer)
}
// 🔑 Eğer ben öğretmensem, öğrenci geldiğinde ben offer göndermeliyim
if (user.role === 'teacher' && !isTeacher) {
const offer = await webRTCServiceRef.current.createOffer(userId)
await signalRServiceRef.current?.sendOffer(classSession.id, userId, offer)
}
}
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) { if (webRTCServiceRef.current) {
// 👇 duplicate connection engelle if (!webRTCServiceRef.current.getPeerConnection(participant.userId)) {
if (!webRTCServiceRef.current.getPeerConnection(userId)) { await webRTCServiceRef.current.createPeerConnection(participant.userId)
await webRTCServiceRef.current.createPeerConnection(userId) }
// 🔑 Eğer ben öğrenci isem, öğretmen için offer gönder
if (user.role === 'student' && participant.isTeacher) {
const offer = await webRTCServiceRef.current.createOffer(participant.userId)
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,
)
} }
} }
setParticipants((prev) => { setParticipants((prev) => {
const existing = prev.find((p) => p.id === userId) const exists = prev.find((p) => p.id === participant.userId)
if (existing) return prev if (exists) return prev
return [ return [
...prev, ...prev,
{ {
id: userId, id: participant.userId,
name, name: participant.userName,
isTeacher, isTeacher: participant.isTeacher,
isAudioMuted: classSettings.autoMuteNewParticipants, isAudioMuted: classSettings.autoMuteNewParticipants,
isVideoMuted: classSettings.defaultCameraState === 'off', isVideoMuted: classSettings.defaultCameraState === 'off',
}, },
] ]
}) })
}
}, },
) )