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)
})
// Setup SignalR event handlers
signalRServiceRef.current.setParticipantJoinHandler(
async (userId: string, name: string, isTeacher: boolean) => {
if (userId === user.id) return
// ExistingParticipants handler
// 🔑 ExistingParticipants handler
signalRServiceRef.current.setExistingParticipantsHandler(
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)
if (webRTCServiceRef.current) {
if (!webRTCServiceRef.current.getPeerConnection(participant.userId)) {
await webRTCServiceRef.current.createPeerConnection(participant.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 öğ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,
)
}
}
// 🔑 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 exists = prev.find((p) => p.id === participant.userId)
if (exists) return prev
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',
},
]
})
},
)