Classroom Video düzenlemesi

This commit is contained in:
Sedat Öztürk 2025-08-30 12:53:28 +03:00
parent 2334f8497c
commit f19a49b227

View file

@ -120,9 +120,6 @@ const RoomDetail: React.FC = () => {
null,
)
const [dragOver, setDragOver] = useState(false)
const [participantsActiveTab, setParticipantsActiveTab] = useState<'participants' | 'attendance'>(
'participants',
)
const fileInputRef = useRef<HTMLInputElement>(null)
const messagesEndRef = useRef<HTMLDivElement>(null)
const [classSettings, setClassSettings] = useState<ClassroomSettingsDto>({
@ -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',
},
]
})
// ✅ 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
}
// ✅ 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)
}
// Küçük id kuralı
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
})
},
)
// 🔑 ExistingParticipants handler
signalRServiceRef.current.setExistingParticipantsHandler(
async (existing: { userId: string; userName: string; isTeacher: boolean }[]) => {
setParticipants((prev) => {
let updated = [...prev]
for (const participant of existing) {
if (participant.userId === user.id) continue
// Katılımcıyı state'e ekle
setParticipants((prev) => {
if (prev.find((p) => p.id === participant.userId)) return prev
return [
...prev,
{
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
}
// ✅ 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)
}
// 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)
await signalRServiceRef.current?.sendOffer(
classSession.id,
participant.userId,
offer,
)
}
}
})()
} else {
console.log('Teacher yok, offer başlatılmadı (existing).')
}
return updated
})
},
)