From 25da8570e0f6e3de7a31d74430ffaabaaa0006ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sedat=20=C3=96zt=C3=BCrk?= Date: Sat, 30 Aug 2025 01:00:26 +0300 Subject: [PATCH] =?UTF-8?q?Classroom=20Videoplayer=20k=C4=B1s=C4=B1mlar?= =?UTF-8?q?=C4=B1=20d=C3=BCzeltildi3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Classroom/ClassroomHub.cs | 17 +++++++++- ui/src/services/classroom/signalr.ts | 4 +++ ui/src/views/classroom/RoomDetail.tsx | 31 ++++++++++++++++++- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/api/src/Kurs.Platform.HttpApi.Host/Classroom/ClassroomHub.cs b/api/src/Kurs.Platform.HttpApi.Host/Classroom/ClassroomHub.cs index f577a41a..4c9c59e6 100644 --- a/api/src/Kurs.Platform.HttpApi.Host/Classroom/ClassroomHub.cs +++ b/api/src/Kurs.Platform.HttpApi.Host/Classroom/ClassroomHub.cs @@ -7,6 +7,7 @@ using Kurs.Platform.Entities; using Microsoft.Extensions.Logging; using Volo.Abp.Guids; using Volo.Abp.Users; +using System.Linq; namespace Kurs.Platform.Classrooms; @@ -82,6 +83,20 @@ public class ClassroomHub : Hub await Groups.AddToGroupAsync(Context.ConnectionId, sessionId.ToString()); + // 🔑 Yeni katılana mevcut katılımcıları gönder + var existingParticipants = await _participantRepository.GetListAsync(x => x.SessionId == sessionId); + var others = existingParticipants + .Where(x => x.ConnectionId != Context.ConnectionId) + .Select(x => new + { + UserId = x.UserId, + UserName = x.UserName, + IsTeacher = x.IsTeacher + }) + .ToList(); + + await Clients.Caller.SendAsync("ExistingParticipants", others); + await Clients.Group(sessionId.ToString()) .SendAsync("ParticipantJoined", userId, userName); } @@ -115,7 +130,7 @@ public class ClassroomHub : Hub await Clients.Group(sessionId.ToString()) .SendAsync("ParticipantLeft", _currentUser.Id.ToString()); - + _logger.LogInformation($"User {_currentUser} left class {sessionId}"); } diff --git a/ui/src/services/classroom/signalr.ts b/ui/src/services/classroom/signalr.ts index 8365fe0d..b75e0803 100644 --- a/ui/src/services/classroom/signalr.ts +++ b/ui/src/services/classroom/signalr.ts @@ -383,6 +383,10 @@ export class SignalRService { await this.connection.invoke('SendIceCandidate', sessionId, targetUserId, candidate) } + setExistingParticipantsHandler(callback: (participants: any[]) => void) { + this.connection.on('ExistingParticipants', callback) + } + setAttendanceUpdatedHandler(callback: (record: ClassroomAttendanceDto) => void) { this.onAttendanceUpdate = callback } diff --git a/ui/src/views/classroom/RoomDetail.tsx b/ui/src/views/classroom/RoomDetail.tsx index 5dd5c083..f4fe2d71 100644 --- a/ui/src/views/classroom/RoomDetail.tsx +++ b/ui/src/views/classroom/RoomDetail.tsx @@ -274,7 +274,7 @@ const RoomDetail: React.FC = () => { webRTCServiceRef.current.createPeerConnection(userId) // ✅ Sadece teacher offer gönderecek - if (user.role === 'student') { + if (user.role === 'teacher') { const offer = await webRTCServiceRef.current.createOffer(userId) await signalRServiceRef.current?.sendOffer(classSession.id, userId, offer) } @@ -296,6 +296,35 @@ const RoomDetail: React.FC = () => { }) }) + signalRServiceRef.current.setExistingParticipantsHandler(async (existing) => { + console.log('Existing participants:', existing) + + if (webRTCServiceRef.current) { + for (const p of existing) { + // Peer connection oluştur + await webRTCServiceRef.current?.createPeerConnection(p.userId) + + // Eğer ben öğretmensem → herkese offer gönder + if (user.role === 'teacher') { + const offer = await webRTCServiceRef.current.createOffer(p.userId) + await signalRServiceRef.current?.sendOffer(classSession.id, p.userId, offer) + } + } + } + + // State güncelle + setParticipants((prev) => [ + ...prev, + ...existing.map((p) => ({ + id: p.userId, + name: p.userName, + isTeacher: p.isTeacher, + isAudioMuted: classSettings.autoMuteNewParticipants, + isVideoMuted: classSettings.defaultCameraState === 'off', + })), + ]) + }) + signalRServiceRef.current.setParticipantLeaveHandler((userId) => { console.log(`Participant left: ${userId}`)