mirror of
https://github.com/pion/ice.git
synced 2025-09-26 19:41:11 +08:00
Include ufrag in generated ICE candidates
Include ufrag extension in the ICE candidates generated by the ICE agent
This commit is contained in:
11
agent.go
11
agent.go
@@ -799,6 +799,7 @@ func (a *Agent) addCandidate(ctx context.Context, cand Candidate, candidateConn
|
||||
}
|
||||
}
|
||||
|
||||
a.setCandidateExtensions(cand)
|
||||
cand.start(a, candidateConn, a.startedCh)
|
||||
|
||||
set = append(set, cand)
|
||||
@@ -818,6 +819,16 @@ func (a *Agent) addCandidate(ctx context.Context, cand Candidate, candidateConn
|
||||
})
|
||||
}
|
||||
|
||||
func (a *Agent) setCandidateExtensions(cand Candidate) {
|
||||
err := cand.AddExtension(CandidateExtension{
|
||||
Key: "ufrag",
|
||||
Value: a.localUfrag,
|
||||
})
|
||||
if err != nil {
|
||||
a.log.Errorf("Failed to add ufrag extension to candidate: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// GetRemoteCandidates returns the remote candidates.
|
||||
func (a *Agent) GetRemoteCandidates() ([]Candidate, error) {
|
||||
var res []Candidate
|
||||
|
@@ -2071,3 +2071,42 @@ func TestAgentGracefulCloseDeadlock(t *testing.T) {
|
||||
closeNow.Done()
|
||||
closed.Wait()
|
||||
}
|
||||
|
||||
func TestSetCandidatesUfrag(t *testing.T) {
|
||||
var config AgentConfig
|
||||
|
||||
agent, err := NewAgent(&config)
|
||||
if err != nil {
|
||||
t.Fatalf("Error constructing ice.Agent: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
require.NoError(t, agent.Close())
|
||||
}()
|
||||
|
||||
dummyConn := &net.UDPConn{}
|
||||
|
||||
for i := 0; i < 5; i++ {
|
||||
cfg := CandidateHostConfig{
|
||||
Network: "udp",
|
||||
Address: "192.168.0.2",
|
||||
Port: 1000 + i,
|
||||
Component: 1,
|
||||
}
|
||||
|
||||
cand, errCand := NewCandidateHost(&cfg)
|
||||
require.NoError(t, errCand)
|
||||
|
||||
err = agent.addCandidate(context.Background(), cand, dummyConn)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
actualCandidates, err := agent.GetLocalCandidates()
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, candidate := range actualCandidates {
|
||||
ext, ok := candidate.GetExtension("ufrag")
|
||||
|
||||
require.True(t, ok)
|
||||
require.Equal(t, agent.localUfrag, ext.Value)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user