Skip to content

Commit

Permalink
fix(ice): buffer candidates if received before sdp negotiation comple…
Browse files Browse the repository at this point in the history
…tes (#204)
  • Loading branch information
tarrencev authored Oct 1, 2020
1 parent 2be39bb commit 1a066aa
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion pkg/webrtctransport.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type WebRTCTransport struct {
pc *webrtc.PeerConnection
me webrtc.MediaEngine
mu sync.RWMutex
candidates []webrtc.ICECandidateInit
session *Session
senders []Sender
routers map[string]Router
Expand Down Expand Up @@ -196,6 +197,16 @@ func (p *WebRTCTransport) SetRemoteDescription(desc webrtc.SessionDescription) e
return err
}

if len(p.candidates) > 0 {
for _, candidate := range p.candidates {
err := p.pc.AddICECandidate(candidate)
if err != nil {
log.Errorf("Error adding ice candidate %s", err)
}
}
p.candidates = nil
}

return nil
}

Expand All @@ -206,7 +217,11 @@ func (p *WebRTCTransport) LocalDescription() *webrtc.SessionDescription {

// AddICECandidate to peer connection
func (p *WebRTCTransport) AddICECandidate(candidate webrtc.ICECandidateInit) error {
return p.pc.AddICECandidate(candidate)
if p.pc.RemoteDescription() != nil {
return p.pc.AddICECandidate(candidate)
}
p.candidates = append(p.candidates, candidate)
return nil
}

// OnICECandidate handler
Expand Down

0 comments on commit 1a066aa

Please sign in to comment.