Classroom Videoplayer kısımları düzeltildi
This commit is contained in:
parent
04b57e6a92
commit
3587446042
3 changed files with 58 additions and 39 deletions
|
|
@ -97,11 +97,11 @@ public class ClassroomHub : Hub
|
||||||
|
|
||||||
await Clients.Caller.SendAsync("ExistingParticipants", others);
|
await Clients.Caller.SendAsync("ExistingParticipants", others);
|
||||||
|
|
||||||
|
// 🔑 Grup üyelerine yeni katılanı öğretmen bilgisiyle bildir
|
||||||
await Clients.Group(sessionId.ToString())
|
await Clients.Group(sessionId.ToString())
|
||||||
.SendAsync("ParticipantJoined", userId, userName);
|
.SendAsync("ParticipantJoined", userId, userName, isTeacher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
[HubMethodName("LeaveClass")]
|
[HubMethodName("LeaveClass")]
|
||||||
public async Task LeaveClassAsync(Guid sessionId)
|
public async Task LeaveClassAsync(Guid sessionId)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ export class SignalRService {
|
||||||
private connection!: signalR.HubConnection
|
private connection!: signalR.HubConnection
|
||||||
private isConnected: boolean = false
|
private isConnected: boolean = false
|
||||||
private onAttendanceUpdate?: (record: ClassroomAttendanceDto) => void
|
private onAttendanceUpdate?: (record: ClassroomAttendanceDto) => void
|
||||||
private onParticipantJoined?: (userId: string, name: string) => void
|
private onParticipantJoined?: (userId: string, name: string, isTeacher: boolean) => void
|
||||||
private onParticipantLeft?: (userId: string) => void
|
private onParticipantLeft?: (userId: string) => void
|
||||||
private onChatMessage?: (message: ClassroomChatDto) => void
|
private onChatMessage?: (message: ClassroomChatDto) => void
|
||||||
private onParticipantMuted?: (userId: string, isMuted: boolean) => void
|
private onParticipantMuted?: (userId: string, isMuted: boolean) => void
|
||||||
|
|
@ -39,8 +39,8 @@ export class SignalRService {
|
||||||
this.onAttendanceUpdate?.(record)
|
this.onAttendanceUpdate?.(record)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.connection.on('ParticipantJoined', (userId: string, name: string) => {
|
this.connection.on('ParticipantJoined', (userId: string, name: string, isTeacher: boolean) => {
|
||||||
this.onParticipantJoined?.(userId, name)
|
this.onParticipantJoined?.(userId, name, isTeacher)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.connection.on('ParticipantLeft', (userId: string) => {
|
this.connection.on('ParticipantLeft', (userId: string) => {
|
||||||
|
|
@ -391,7 +391,7 @@ export class SignalRService {
|
||||||
this.onAttendanceUpdate = callback
|
this.onAttendanceUpdate = callback
|
||||||
}
|
}
|
||||||
|
|
||||||
setParticipantJoinHandler(callback: (userId: string, name: string) => void) {
|
setParticipantJoinHandler(callback: (userId: string, name: string, isTeacher: boolean) => void) {
|
||||||
this.onParticipantJoined = callback
|
this.onParticipantJoined = callback
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -265,16 +265,23 @@ const RoomDetail: React.FC = () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
// Setup SignalR event handlers
|
// Setup SignalR event handlers
|
||||||
signalRServiceRef.current.setParticipantJoinHandler(async (userId, name) => {
|
signalRServiceRef.current.setParticipantJoinHandler(
|
||||||
|
async (userId: string, name: string, isTeacher: boolean) => {
|
||||||
if (userId === user.id) return
|
if (userId === user.id) return
|
||||||
|
|
||||||
console.log(`Participant joined: ${name}`)
|
console.log(`Participant joined: ${name}, isTeacher: ${isTeacher}`)
|
||||||
|
|
||||||
if (webRTCServiceRef.current) {
|
if (webRTCServiceRef.current) {
|
||||||
webRTCServiceRef.current.createPeerConnection(userId)
|
await webRTCServiceRef.current.createPeerConnection(userId)
|
||||||
|
|
||||||
// ✅ Sadece teacher offer gönderecek
|
// 🔑 Eğer ben öğrenci isem, öğretmen geldiğinde ben offer göndermeliyim
|
||||||
if (user.role === 'teacher') {
|
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)
|
const offer = await webRTCServiceRef.current.createOffer(userId)
|
||||||
await signalRServiceRef.current?.sendOffer(classSession.id, userId, offer)
|
await signalRServiceRef.current?.sendOffer(classSession.id, userId, offer)
|
||||||
}
|
}
|
||||||
|
|
@ -288,25 +295,37 @@ const RoomDetail: React.FC = () => {
|
||||||
{
|
{
|
||||||
id: userId,
|
id: userId,
|
||||||
name,
|
name,
|
||||||
isTeacher: false,
|
isTeacher, // ✅ artık backend’den gelen değer
|
||||||
isAudioMuted: classSettings.autoMuteNewParticipants,
|
isAudioMuted: classSettings.autoMuteNewParticipants,
|
||||||
isVideoMuted: classSettings.defaultCameraState === 'off',
|
isVideoMuted: classSettings.defaultCameraState === 'off',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
})
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
// Existing participants handler
|
||||||
signalRServiceRef.current.setExistingParticipantsHandler(async (existing) => {
|
signalRServiceRef.current.setExistingParticipantsHandler(async (existing) => {
|
||||||
console.log('Existing participants:', existing)
|
console.log('Existing participants:', existing)
|
||||||
|
|
||||||
if (webRTCServiceRef.current) {
|
if (webRTCServiceRef.current) {
|
||||||
for (const p of existing) {
|
for (const p of existing) {
|
||||||
await webRTCServiceRef.current.createPeerConnection(p.userId)
|
const id = p.userId || p.UserId
|
||||||
|
const name = p.userName || p.UserName
|
||||||
|
const isTeacher = p.isTeacher ?? p.IsTeacher
|
||||||
|
|
||||||
// ✅ Eğer ben öğrenci isem → mevcut öğretmene offer gönderirim
|
await webRTCServiceRef.current.createPeerConnection(id)
|
||||||
if (user.role === 'student' && p.isTeacher) {
|
|
||||||
const offer = await webRTCServiceRef.current.createOffer(p.userId)
|
// öğrenci → öğretmen
|
||||||
await signalRServiceRef.current?.sendOffer(classSession.id, p.userId, offer)
|
if (user.role === 'student' && isTeacher) {
|
||||||
|
const offer = await webRTCServiceRef.current.createOffer(id)
|
||||||
|
await signalRServiceRef.current?.sendOffer(classSession.id, id, offer)
|
||||||
|
}
|
||||||
|
|
||||||
|
// öğretmen → öğrenci
|
||||||
|
if (user.role === 'teacher' && !isTeacher) {
|
||||||
|
const offer = await webRTCServiceRef.current.createOffer(id)
|
||||||
|
await signalRServiceRef.current?.sendOffer(classSession.id, id, offer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -314,9 +333,9 @@ const RoomDetail: React.FC = () => {
|
||||||
setParticipants((prev) => [
|
setParticipants((prev) => [
|
||||||
...prev,
|
...prev,
|
||||||
...existing.map((p) => ({
|
...existing.map((p) => ({
|
||||||
id: p.userId,
|
id: p.userId || p.UserId,
|
||||||
name: p.userName,
|
name: p.userName || p.UserName,
|
||||||
isTeacher: p.isTeacher,
|
isTeacher: p.isTeacher ?? p.IsTeacher,
|
||||||
isAudioMuted: classSettings.autoMuteNewParticipants,
|
isAudioMuted: classSettings.autoMuteNewParticipants,
|
||||||
isVideoMuted: classSettings.defaultCameraState === 'off',
|
isVideoMuted: classSettings.defaultCameraState === 'off',
|
||||||
})),
|
})),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue