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