Classroom video
This commit is contained in:
parent
29da0f2ea4
commit
8e8bca6c5a
1 changed files with 46 additions and 62 deletions
|
|
@ -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}`)
|
||||
|
||||
if (webRTCServiceRef.current) {
|
||||
await webRTCServiceRef.current.createPeerConnection(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 öğ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 existing = prev.find((p) => p.id === userId)
|
||||
if (existing) return prev
|
||||
return [
|
||||
...prev,
|
||||
{
|
||||
id: userId,
|
||||
name,
|
||||
isTeacher, // ✅ artık backend’den gelen değer
|
||||
isAudioMuted: classSettings.autoMuteNewParticipants,
|
||||
isVideoMuted: classSettings.defaultCameraState === 'off',
|
||||
},
|
||||
]
|
||||
})
|
||||
},
|
||||
console.log(
|
||||
`Existing participant: ${participant.userName}, isTeacher: ${participant.isTeacher}`,
|
||||
)
|
||||
|
||||
// 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)
|
||||
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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
setParticipants((prev) => {
|
||||
const existing = prev.find((p) => p.id === userId)
|
||||
if (existing) return prev
|
||||
const exists = prev.find((p) => p.id === participant.userId)
|
||||
if (exists) return prev
|
||||
return [
|
||||
...prev,
|
||||
{
|
||||
id: userId,
|
||||
name,
|
||||
isTeacher,
|
||||
id: participant.userId,
|
||||
name: participant.userName,
|
||||
isTeacher: participant.isTeacher,
|
||||
isAudioMuted: classSettings.autoMuteNewParticipants,
|
||||
isVideoMuted: classSettings.defaultCameraState === 'off',
|
||||
},
|
||||
]
|
||||
})
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue