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

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

@@ -110,18 +110,20 @@ func JoinWithOffer(roomID string, peerID string, offer webrtc.SessionDescription
return peerConnection.LocalDescription(), nil
}
// AddICECandidate добавляет ICE-кандидата к пиру
func AddICECandidate(roomID string, peerID string, candidate webrtc.ICECandidateInit) error {
// LeaveRoom позволяет пиру покинуть комнату
func LeaveRoom(roomID string, peerID string) error {
room, exists := GetRoom(roomID)
if !exists {
return ErrRoomNotFound
}
for _, peer := range room.Peers {
for i, peer := range room.Peers {
if peer.PeerID == peerID {
return peer.PeerConnection.AddICECandidate(candidate)
peer.PeerConnection.Close()
room.Peers = append(room.Peers[:i], room.Peers[i+1:]...)
break
}
}
return ErrPeerNotFound
return nil
}