@@ -218,7 +218,9 @@ func (w *WorkerICE) reCreateAgent(dialerCancel context.CancelFunc, candidates []
218
218
return nil , err
219
219
}
220
220
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 {
222
224
return nil , err
223
225
}
224
226
@@ -365,26 +367,17 @@ func (w *WorkerICE) onICECandidate(candidate ice.Candidate) {
365
367
}()
366
368
}
367
369
368
- func (w * WorkerICE ) onICESelectedCandidatePair (c1 ice. Candidate , c2 ice.Candidate ) {
370
+ func (w * WorkerICE ) onICESelectedCandidatePair (agent * icemaker. ThreadSafeAgent , c1 , c2 ice.Candidate ) {
369
371
w .log .Debugf ("selected candidate pair [local <-> remote] -> [%s <-> %s], peer %s" , c1 .String (), c2 .String (),
370
372
w .config .Key )
371
373
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" )
383
377
return
384
378
}
385
- w .muxAgent .Unlock ()
386
379
387
- duration := time .Duration (pair .CurrentRoundTripTime () * float64 (time .Second ))
380
+ duration := time .Duration (pairStat .CurrentRoundTripTime * float64 (time .Second ))
388
381
if err := w .statusRecorder .UpdateLatency (w .config .Key , duration ); err != nil {
389
382
w .log .Debugf ("failed to update latency for peer: %s" , err )
390
383
return
0 commit comments