TURN сервер для выхода за сложные NAT

This commit is contained in:
set
2026-03-14 23:08:18 +02:00
parent ef591072f3
commit b6d5780584
3 changed files with 125 additions and 0 deletions

View File

@@ -12,8 +12,15 @@ import (
var (
pendingMu sync.Mutex
pendingCandidates = map[string][]webrtc.ICECandidateInit{} // key: roomID|peerID
renegMu sync.Map
)
func getRenegLock(roomID, peerID string) *sync.Mutex {
k := peerKey(roomID, peerID)
v, _ := renegMu.LoadOrStore(k, &sync.Mutex{})
return v.(*sync.Mutex)
}
func peerKey(roomID, peerID string) string {
return roomID + "|" + peerID
}
@@ -92,6 +99,15 @@ func SetupForwardingForPeer(roomID string, publisherPeerID string, publisherPC *
}
func renegotiatePeer(roomID, peerID string, pc *webrtc.PeerConnection) error {
lock := getRenegLock(roomID, peerID)
lock.Lock()
defer lock.Unlock()
// Не начинаем новую negotiation поверх текущей
if pc.SignalingState() != webrtc.SignalingStateStable {
return nil
}
offer, err := pc.CreateOffer(nil)
if err != nil {
return err