From 7c897626c1f2edbc3b30b6008abcba3bcabfda85 Mon Sep 17 00:00:00 2001 From: ZHENK Date: Tue, 8 Dec 2020 00:17:51 +1300 Subject: [PATCH] Accept nil Candidate in AddRemoteCandidate Allow a user to pass a nil Candidate. We perform no actions off of this currently. Until browsers implement end-of-candidates consistently it isn't something we can do. Relates to pion/webrtc#1212 and #271 --- agent.go | 6 +++++- agent_test.go | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/agent.go b/agent.go index 82de746..9f1ac6a 100644 --- a/agent.go +++ b/agent.go @@ -706,7 +706,11 @@ func (a *Agent) checkKeepalive() { // AddRemoteCandidate adds a new remote candidate func (a *Agent) AddRemoteCandidate(c Candidate) error { - // canot check for network yet because it might not be applied + if c == nil { + return nil + } + + // cannot check for network yet because it might not be applied // when mDNS hostame is used. if c.TCPType() == TCPTypeActive { // TCP Candidates with tcptype active will probe server passive ones, so diff --git a/agent_test.go b/agent_test.go index 05361f3..3377729 100644 --- a/agent_test.go +++ b/agent_test.go @@ -1686,3 +1686,11 @@ func TestLiteLifecycle(t *testing.T) { <-bFailed assert.NoError(t, bAgent.Close()) } + +func TestNilCandidate(t *testing.T) { + a, err := NewAgent(&AgentConfig{}) + assert.NoError(t, err) + + assert.NoError(t, a.AddRemoteCandidate(nil)) + assert.NoError(t, a.Close()) +}