Classroom Video düzenlemesi
This commit is contained in:
parent
2334f8497c
commit
f19a49b227
1 changed files with 55 additions and 57 deletions
|
|
@ -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',
|
||||||
},
|
})
|
||||||
]
|
}
|
||||||
|
|
||||||
|
// ✅ 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)
|
||||||
|
}
|
||||||
|
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
|
||||||
})
|
})
|
||||||
|
|
||||||
// ✅ 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)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
// 🔑 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 }[]) => {
|
||||||
for (const participant of existing) {
|
setParticipants((prev) => {
|
||||||
if (participant.userId === user.id) continue
|
let updated = [...prev]
|
||||||
|
|
||||||
// Katılımcıyı state'e ekle
|
for (const participant of existing) {
|
||||||
setParticipants((prev) => {
|
if (participant.userId === user.id) continue
|
||||||
if (prev.find((p) => p.id === participant.userId)) return prev
|
if (!updated.find((p) => p.id === participant.userId)) {
|
||||||
return [
|
updated.push({
|
||||||
...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
|
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
// ✅ güncel listede öğretmen var mı?
|
||||||
if (user.id < participant.userId) {
|
const teacherExists = updated.some((p) => p.isTeacher)
|
||||||
const offer = await webRTCServiceRef.current!.createOffer(participant.userId)
|
if (teacherExists) {
|
||||||
await signalRServiceRef.current?.sendOffer(classSession.id, participant.userId, offer)
|
;(async () => {
|
||||||
|
for (const participant of existing) {
|
||||||
|
if (participant.userId === user.id) continue
|
||||||
|
if (!webRTCServiceRef.current?.getPeerConnection(participant.userId)) {
|
||||||
|
await webRTCServiceRef.current?.createPeerConnection(participant.userId)
|
||||||
|
}
|
||||||
|
if (user.id < participant.userId) {
|
||||||
|
const offer = await webRTCServiceRef.current!.createOffer(participant.userId)
|
||||||
|
await signalRServiceRef.current?.sendOffer(
|
||||||
|
classSession.id,
|
||||||
|
participant.userId,
|
||||||
|
offer,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
} else {
|
||||||
|
console.log('Teacher yok, offer başlatılmadı (existing).')
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
return updated
|
||||||
|
})
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue