diff --git a/relay.go b/relay.go index 5b389bc..735098b 100644 --- a/relay.go +++ b/relay.go @@ -228,6 +228,9 @@ func newCall(mainOffer receivedSignal, r *activeRelay) { return } + // Close peer connection + defer mainPeerConnection.Close() + // Check if the connection is closed mainPeerConnection.OnConnectionStateChange(func(s webrtc.PeerConnectionState) { if s == webrtc.PeerConnectionStateClosed { @@ -236,9 +239,6 @@ func newCall(mainOffer receivedSignal, r *activeRelay) { } }) - // Close peer connection - defer mainPeerConnection.Close() - // Forward ice candidates mainPeerConnection.OnICECandidate(func(c *webrtc.ICECandidate) { if c == nil || r.closed {