Skip to content

Commit

Permalink
Fix AddRemoteCandidate to accept nil candidate
Browse files Browse the repository at this point in the history
empty candidate.Candidate won't make an error when pass into pion/ice
  • Loading branch information
scorpionknifes committed Dec 7, 2020
1 parent 5e5f171 commit 667ad8f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,12 @@ 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
// accept nil candidate. aka end-of-candidates will not fail
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
Expand Down
11 changes: 11 additions & 0 deletions agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1686,3 +1686,14 @@ func TestLiteLifecycle(t *testing.T) {
<-bFailed
assert.NoError(t, bAgent.Close())
}

func TestNilCandidate(t *testing.T) {
var config AgentConfig
a, err := NewAgent(&config)
if err != nil {
t.Fatalf("Error constructing ice.Agent: %v", err)
}

err = a.AddRemoteCandidate(nil)
assert.NoError(t, err)
}

0 comments on commit 667ad8f

Please sign in to comment.