@@ -283,22 +283,6 @@ func (c *Conn) negotiate() {
283
283
return
284
284
}
285
285
286
- // The ICE transport resets when the remote description is updated.
287
- // Adding ICE candidates before this point causes a failed connection,
288
- // because the candidate would be lost.
289
- c .pendingCandidatesMutex .Lock ()
290
- defer c .pendingCandidatesMutex .Unlock ()
291
- for _ , pendingCandidate := range c .pendingRemoteCandidates {
292
- c .opts .Logger .Debug (context .Background (), "flushing remote candidate" )
293
- err := c .rtc .AddICECandidate (pendingCandidate )
294
- if err != nil {
295
- _ = c .CloseWithError (xerrors .Errorf ("flush pending candidates: %w" , err ))
296
- return
297
- }
298
- }
299
- c .pendingCandidatesFlushed = true
300
- c .opts .Logger .Debug (context .Background (), "flushed remote candidates" )
301
-
302
286
if ! c .offerrer {
303
287
answer , err := c .rtc .CreateAnswer (& webrtc.AnswerOptions {})
304
288
if err != nil {
@@ -320,6 +304,22 @@ func (c *Conn) negotiate() {
320
304
case c .localSessionDescriptionChannel <- answer :
321
305
}
322
306
}
307
+
308
+ // The ICE transport resets when the remote description is updated.
309
+ // Adding ICE candidates before this point causes a failed connection,
310
+ // because the candidate would be lost.
311
+ c .pendingCandidatesMutex .Lock ()
312
+ defer c .pendingCandidatesMutex .Unlock ()
313
+ for _ , pendingCandidate := range c .pendingRemoteCandidates {
314
+ c .opts .Logger .Debug (context .Background (), "flushing remote candidate" )
315
+ err := c .rtc .AddICECandidate (pendingCandidate )
316
+ if err != nil {
317
+ _ = c .CloseWithError (xerrors .Errorf ("flush pending candidates: %w" , err ))
318
+ return
319
+ }
320
+ }
321
+ c .pendingCandidatesFlushed = true
322
+ c .opts .Logger .Debug (context .Background (), "flushed remote candidates" )
323
323
}
324
324
325
325
// LocalCandidate returns a channel that emits when a local candidate
0 commit comments