Оптимизация кода и выход пира из комнаты

This commit is contained in:
set
2026-03-11 19:44:43 +02:00
parent 242456bb3c
commit b81ae8a3c0
3 changed files with 28 additions and 10 deletions

View File

@@ -7,9 +7,6 @@ import (
"github.com/pion/webrtc/v4"
)
// SFU -> Java signaling: отправить server-offer для конкретного peer
var OnServerOffer func(roomID string, peerID string, offer webrtc.SessionDescription)
// Вызывается при JoinWithOffer для ретрансляции RTP пакетов от издателя к другим участникам комнаты
func SetupForwardingForPeer(roomID string, publisherPeerID string, publisherPC *webrtc.PeerConnection) {
publisherPC.OnTrack(func(remote *webrtc.TrackRemote, _ *webrtc.RTPReceiver) {
@@ -91,8 +88,24 @@ func renegotiatePeer(roomID, peerID string, pc *webrtc.PeerConnection) error {
return nil
}
// Java -> SFU: answer клиента на server-offer
func HandleClientAnswer(roomID, peerID string, answer webrtc.SessionDescription) error {
// Добавляет ICE-кандидата к пиру
func AddICECandidate(roomID string, peerID string, candidate webrtc.ICECandidateInit) error {
room, exists := GetRoom(roomID)
if !exists {
return ErrRoomNotFound
}
for _, peer := range room.Peers {
if peer.PeerID == peerID {
return peer.PeerConnection.AddICECandidate(candidate)
}
}
return ErrPeerNotFound
}
// Обрабатывает SDP ответ от клиента при renegotiation
func HandleClientAnswer(roomID string, peerID string, answer webrtc.SessionDescription) error {
roomsMu.RLock()
room, ok := rooms[roomID]
if !ok {