Classroom Video düzenlemesi

This commit is contained in:
Sedat Öztürk 2025-08-30 12:14:30 +03:00
parent 8ffc6f6439
commit 2334f8497c

View file

@ -136,6 +136,8 @@ const RoomDetail: React.FC = () => {
autoMuteNewParticipants: true, autoMuteNewParticipants: true,
}) })
const hasTeacher = (list: ClassroomParticipantDto[]) => list.some((p) => p.isTeacher)
const signalRServiceRef = useRef<SignalRService>() const signalRServiceRef = useRef<SignalRService>()
const webRTCServiceRef = useRef<WebRTCService>() const webRTCServiceRef = useRef<WebRTCService>()
@ -270,35 +272,9 @@ const RoomDetail: React.FC = () => {
console.log(`Participant joined: ${name}, isTeacher: ${isTeacher}`) console.log(`Participant joined: ${name}, isTeacher: ${isTeacher}`)
if (webRTCServiceRef.current) { // Katılımcıyı state'e ekle
if (!webRTCServiceRef.current.getPeerConnection(userId)) {
await webRTCServiceRef.current.createPeerConnection(userId)
}
// student → teacher
if (user.role === 'student' && isTeacher) {
const offer = await webRTCServiceRef.current.createOffer(userId)
await signalRServiceRef.current?.sendOffer(classSession.id, userId, offer)
}
// teacher → student
if (user.role === 'teacher' && !isTeacher) {
const offer = await webRTCServiceRef.current.createOffer(userId)
await signalRServiceRef.current?.sendOffer(classSession.id, userId, offer)
}
// teacher ↔ teacher
if (user.role === 'teacher' && isTeacher) {
if (user.id < userId) {
const offer = await webRTCServiceRef.current.createOffer(userId)
await signalRServiceRef.current?.sendOffer(classSession.id, userId, offer)
}
}
}
setParticipants((prev) => { setParticipants((prev) => {
const exists = prev.find((p) => p.id === userId) if (prev.find((p) => p.id === userId)) return prev
if (exists) return prev
return [ return [
...prev, ...prev,
{ {
@ -310,6 +286,23 @@ const RoomDetail: React.FC = () => {
}, },
] ]
}) })
// ✅ 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
}
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)
}
}, },
) )
@ -319,52 +312,9 @@ const RoomDetail: React.FC = () => {
for (const participant of existing) { for (const participant of existing) {
if (participant.userId === user.id) continue if (participant.userId === user.id) continue
console.log( // Katılımcıyı state'e ekle
`Existing participant: ${participant.userName}, isTeacher: ${participant.isTeacher}`,
)
if (webRTCServiceRef.current) {
if (!webRTCServiceRef.current.getPeerConnection(participant.userId)) {
await webRTCServiceRef.current.createPeerConnection(participant.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,
)
}
// 🔑 Öğretmen ↔ Öğretmen
if (user.role === 'teacher' && participant.isTeacher) {
// idsi küçük olan offer göndersin
if (user.id < participant.userId) {
const offer = await webRTCServiceRef.current.createOffer(participant.userId)
await signalRServiceRef.current?.sendOffer(
classSession.id,
participant.userId,
offer,
)
}
}
}
setParticipants((prev) => { setParticipants((prev) => {
const exists = prev.find((p) => p.id === participant.userId) if (prev.find((p) => p.id === participant.userId)) return prev
if (exists) return prev
return [ return [
...prev, ...prev,
{ {
@ -377,6 +327,27 @@ const RoomDetail: React.FC = () => {
] ]
}) })
} }
// ✅ 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
}
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)
}
}
}, },
) )