Include ufrag in generated ICE candidates

Include ufrag extension in the ICE candidates generated by the ICE agent
This commit is contained in:
Joe Turki
2025-01-30 01:14:01 -06:00
parent 141df5a086
commit d21ae5e0e5
2 changed files with 50 additions and 0 deletions

View File

@@ -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

View File

@@ -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)
}
}