Skip to content

Commit aa1e664

Browse files
committed
Flush after handshake
1 parent a2a4da4 commit aa1e664

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

peer/conn.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -283,22 +283,6 @@ func (c *Conn) negotiate() {
283283
return
284284
}
285285

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-
302286
if !c.offerrer {
303287
answer, err := c.rtc.CreateAnswer(&webrtc.AnswerOptions{})
304288
if err != nil {
@@ -320,6 +304,22 @@ func (c *Conn) negotiate() {
320304
case c.localSessionDescriptionChannel <- answer:
321305
}
322306
}
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")
323323
}
324324

325325
// LocalCandidate returns a channel that emits when a local candidate

0 commit comments

Comments
 (0)