Classroom Videoplayer kısımları düzeltildi3

This commit is contained in:
Sedat Öztürk 2025-08-30 00:44:12 +03:00
parent 42694bf681
commit 79b0aa42e3
3 changed files with 22 additions and 9 deletions

View file

@ -114,7 +114,8 @@ public class ClassroomHub : Hub
} }
await Clients.Group(sessionId.ToString()) await Clients.Group(sessionId.ToString())
.SendAsync("ParticipantLeft", _currentUser); .SendAsync("ParticipantLeft", _currentUser.Id.ToString());
_logger.LogInformation($"User {_currentUser} left class {sessionId}"); _logger.LogInformation($"User {_currentUser} left class {sessionId}");
} }

View file

@ -1,7 +1,6 @@
import React, { useRef, useEffect } from 'react' import React, { useRef, useEffect } from 'react'
import { FaMicrophoneSlash, FaVideoSlash } from 'react-icons/fa' import { FaMicrophoneSlash, FaVideoSlash } from 'react-icons/fa'
// VideoOff component replacement
const VideoOff: React.FC<{ size?: number; className?: string }> = ({ const VideoOff: React.FC<{ size?: number; className?: string }> = ({
size = 24, size = 24,
className = '', className = '',
@ -31,8 +30,19 @@ export const VideoPlayer: React.FC<VideoPlayerProps> = ({
const videoRef = useRef<HTMLVideoElement>(null) const videoRef = useRef<HTMLVideoElement>(null)
useEffect(() => { useEffect(() => {
if (videoRef.current && stream) { const videoEl = videoRef.current
videoRef.current.srcObject = stream if (!videoEl) return
if (stream) {
videoEl.srcObject = stream
} else {
videoEl.srcObject = null // 🟢 ayrıldığında video siyaha düşer
}
return () => {
if (videoEl) {
videoEl.srcObject = null // 🟢 cleanup
}
} }
}, [stream]) }, [stream])

View file

@ -266,17 +266,15 @@ const RoomDetail: React.FC = () => {
// Setup SignalR event handlers // Setup SignalR event handlers
signalRServiceRef.current.setParticipantJoinHandler(async (userId, name) => { signalRServiceRef.current.setParticipantJoinHandler(async (userId, name) => {
// 🔑 Eğer gelen participant bizsek, listeye ekleme
if (userId === user.id) return if (userId === user.id) return
console.log(`Participant joined: ${name}`) console.log(`Participant joined: ${name}`)
// Create WebRTC connection for new participant
if (webRTCServiceRef.current) { if (webRTCServiceRef.current) {
webRTCServiceRef.current.createPeerConnection(userId) webRTCServiceRef.current.createPeerConnection(userId)
// Eğer biz teacher isek offer oluşturup gönderelim // ✅ Sadece teacher offer gönderecek
if (user.role === 'teacher') { if (user.role === 'student') {
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)
} }
@ -300,8 +298,12 @@ const RoomDetail: React.FC = () => {
signalRServiceRef.current.setParticipantLeaveHandler((userId) => { signalRServiceRef.current.setParticipantLeaveHandler((userId) => {
console.log(`Participant left: ${userId}`) console.log(`Participant left: ${userId}`)
setParticipants((prev) => prev.filter((p) => p.id !== userId))
// peer connectionı kapat
webRTCServiceRef.current?.closePeerConnection(userId) webRTCServiceRef.current?.closePeerConnection(userId)
// katılımcıyı stateden sil
setParticipants((prev) => prev.filter((p) => p.id !== userId))
}) })
signalRServiceRef.current.setAttendanceUpdatedHandler((record) => { signalRServiceRef.current.setAttendanceUpdatedHandler((record) => {