Classroom genel düzenlemeler

This commit is contained in:
Sedat Öztürk 2025-08-30 19:19:07 +03:00
parent ab45389299
commit 7c882cb5d8
2 changed files with 26 additions and 7 deletions

View file

@ -83,6 +83,7 @@ public class ClassroomHub : Hub
else else
{ {
participant.UpdateConnectionId(Context.ConnectionId); participant.UpdateConnectionId(Context.ConnectionId);
participant.IsActive = isActive; // Aktiflik durumunu güncelle
await _participantRepository.UpdateAsync(participant, autoSave: true); await _participantRepository.UpdateAsync(participant, autoSave: true);
} }
@ -98,7 +99,6 @@ public class ClassroomHub : Hub
await Groups.AddToGroupAsync(Context.ConnectionId, sessionId.ToString()); await Groups.AddToGroupAsync(Context.ConnectionId, sessionId.ToString());
// 🔑 Yeni katılana mevcut katılımcıları gönder
// 🔑 Yeni katılana mevcut aktif katılımcıları gönder // 🔑 Yeni katılana mevcut aktif katılımcıları gönder
var existingParticipants = await _participantRepository.GetListAsync( var existingParticipants = await _participantRepository.GetListAsync(
x => x.SessionId == sessionId && x.IsActive x => x.SessionId == sessionId && x.IsActive
@ -119,7 +119,7 @@ public class ClassroomHub : Hub
// 🔑 Grup üyelerine yeni katılanı öğretmen bilgisiyle bildir // 🔑 Grup üyelerine yeni katılanı öğretmen bilgisiyle bildir
await Clients.Group(sessionId.ToString()) await Clients.Group(sessionId.ToString())
.SendAsync("ParticipantJoined", userId, userName, isTeacher, true); .SendAsync("ParticipantJoined", userId, userName, isTeacher, isActive);
} }
[HubMethodName("LeaveClass")] [HubMethodName("LeaveClass")]
@ -369,6 +369,18 @@ public class ClassroomHub : Hub
}); });
} }
// 🔑 Participanti pasife al
var participant = await _participantRepository.FirstOrDefaultAsync(
x => x.SessionId == sessionId && x.UserId == participantId
);
if (participant != null)
{
participant.IsActive = false;
await _participantRepository.UpdateAsync(participant, autoSave: true);
}
_logger.LogInformation("👢 Participant {ParticipantId} kicked from session {SessionId}", participantId, sessionId);
// Katılımcı çıkışını bildir // Katılımcı çıkışını bildir
await Clients.Group(sessionId.ToString()).SendAsync("ParticipantLeft", participantId); await Clients.Group(sessionId.ToString()).SendAsync("ParticipantLeft", participantId);
} }
@ -476,6 +488,9 @@ public class ClassroomHub : Hub
}); });
} }
participant.IsActive = false;
await _participantRepository.UpdateAsync(participant, autoSave: true);
// 🔑 3. ParticipantLeft eventi // 🔑 3. ParticipantLeft eventi
await Clients.Group(participant.SessionId.ToString()) await Clients.Group(participant.SessionId.ToString())
.SendAsync("ParticipantLeft", userId.Value); .SendAsync("ParticipantLeft", userId.Value);

View file

@ -282,13 +282,16 @@ const RoomDetail: React.FC = () => {
} }
// ✅ güncel listedeki öğretmen kontrolü // ✅ güncel listedeki öğretmen kontrolü
const teacherExists = updated.some((p) => p.isTeacher) const teacherExists = updated.some((p) => p.isTeacher && p.isActive)
if (teacherExists) { if (teacherExists) {
;(async () => { ;(async () => {
if (!webRTCServiceRef.current?.getPeerConnection(userId)) { if (!webRTCServiceRef.current?.getPeerConnection(userId)) {
await webRTCServiceRef.current?.createPeerConnection(userId) await webRTCServiceRef.current?.createPeerConnection(userId)
} }
if (user.id < userId) {
// sadece aktif katılımcılara offer başlat
if (isActive && user.id < userId) {
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)
} }
@ -324,7 +327,8 @@ const RoomDetail: React.FC = () => {
} }
// ✅ güncel listede öğretmen var mı? // ✅ güncel listede öğretmen var mı?
const teacherExists = updated.some((p) => p.isTeacher) const teacherExists = updated.some((p) => p.isTeacher && p.isActive)
if (teacherExists) { if (teacherExists) {
;(async () => { ;(async () => {
for (const participant of existing) { for (const participant of existing) {
@ -404,7 +408,7 @@ const RoomDetail: React.FC = () => {
user.id, user.id,
user.name, user.name,
user.role === 'teacher', user.role === 'teacher',
true true,
) )
} catch (error) { } catch (error) {
console.error('Failed to initialize services:', error) console.error('Failed to initialize services:', error)
@ -647,7 +651,7 @@ const RoomDetail: React.FC = () => {
studentId, studentId,
randomName, randomName,
false, // öğrenci false, // öğrenci
true // aktif true, // aktif
) )
} }