Skip to content

Commit bd23ab9

Browse files
authored
[client] Fix ICE latency handling (#4501)
The GetSelectedCandidatePair() does not carry the latency information.
1 parent 0c6f671 commit bd23ab9

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

client/internal/peer/worker_ice.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ func (w *WorkerICE) reCreateAgent(dialerCancel context.CancelFunc, candidates []
218218
return nil, err
219219
}
220220

221-
if err := agent.OnSelectedCandidatePairChange(w.onICESelectedCandidatePair); err != nil {
221+
if err := agent.OnSelectedCandidatePairChange(func(c1, c2 ice.Candidate) {
222+
w.onICESelectedCandidatePair(agent, c1, c2)
223+
}); err != nil {
222224
return nil, err
223225
}
224226

@@ -365,26 +367,17 @@ func (w *WorkerICE) onICECandidate(candidate ice.Candidate) {
365367
}()
366368
}
367369

368-
func (w *WorkerICE) onICESelectedCandidatePair(c1 ice.Candidate, c2 ice.Candidate) {
370+
func (w *WorkerICE) onICESelectedCandidatePair(agent *icemaker.ThreadSafeAgent, c1, c2 ice.Candidate) {
369371
w.log.Debugf("selected candidate pair [local <-> remote] -> [%s <-> %s], peer %s", c1.String(), c2.String(),
370372
w.config.Key)
371373

372-
w.muxAgent.Lock()
373-
374-
pair, err := w.agent.GetSelectedCandidatePair()
375-
if err != nil {
376-
w.log.Warnf("failed to get selected candidate pair: %s", err)
377-
w.muxAgent.Unlock()
378-
return
379-
}
380-
if pair == nil {
381-
w.log.Warnf("selected candidate pair is nil, cannot proceed")
382-
w.muxAgent.Unlock()
374+
pairStat, ok := agent.GetSelectedCandidatePairStats()
375+
if !ok {
376+
w.log.Warnf("failed to get selected candidate pair stats")
383377
return
384378
}
385-
w.muxAgent.Unlock()
386379

387-
duration := time.Duration(pair.CurrentRoundTripTime() * float64(time.Second))
380+
duration := time.Duration(pairStat.CurrentRoundTripTime * float64(time.Second))
388381
if err := w.statusRecorder.UpdateLatency(w.config.Key, duration); err != nil {
389382
w.log.Debugf("failed to update latency for peer: %s", err)
390383
return

0 commit comments

Comments
 (0)