Skip to content

Commit c5c8b65

Browse files
committed
Try removing buffered candidates
1 parent 1facda9 commit c5c8b65

File tree

1 file changed

+3
-35
lines changed

1 file changed

+3
-35
lines changed

peer/conn.go

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ func newWithClientOrServer(servers []webrtc.ICEServer, client bool, opts *ConnOp
7777
localCandidateChannel: make(chan webrtc.ICECandidateInit),
7878
localSessionDescriptionChannel: make(chan webrtc.SessionDescription),
7979
remoteSessionDescriptionChannel: make(chan webrtc.SessionDescription),
80-
pendingCandidatesToSend: make([]webrtc.ICECandidateInit, 0),
8180
}
8281
if client {
8382
// If we're the client, we want to flip the echo and
@@ -129,9 +128,6 @@ type Conn struct {
129128

130129
negotiateMutex sync.Mutex
131130

132-
pendingCandidatesToSend []webrtc.ICECandidateInit
133-
pendingCandidatesToSendMutex sync.Mutex
134-
135131
pingChannelID uint16
136132
pingEchoChannelID uint16
137133

@@ -227,16 +223,6 @@ func (c *Conn) init() error {
227223
// Run this in a goroutine so we don't block pion/webrtc
228224
// from continuing.
229225
go func() {
230-
c.pendingCandidatesToSendMutex.Lock()
231-
defer c.pendingCandidatesToSendMutex.Unlock()
232-
// If the remote description hasn't been set yet, we queue the send of these candidates.
233-
// It may work to send these immediately, but at the time of writing this package is
234-
// unstable, so better being safe than sorry.
235-
if c.rtc.RemoteDescription() == nil {
236-
c.pendingCandidatesToSend = append(c.pendingCandidatesToSend, iceCandidate.ToJSON())
237-
c.opts.Logger.Debug(context.Background(), "buffering local candidate")
238-
return
239-
}
240226
c.opts.Logger.Debug(context.Background(), "sending local candidate")
241227
select {
242228
case <-c.closed:
@@ -336,24 +322,6 @@ func (c *Conn) negotiate() {
336322
}
337323
c.opts.Logger.Debug(context.Background(), "sent answer")
338324
}
339-
340-
// Flush bufferred candidates after both sides have been negotiated!
341-
go func() {
342-
c.pendingCandidatesToSendMutex.Lock()
343-
defer c.pendingCandidatesToSendMutex.Unlock()
344-
for _, pendingCandidate := range c.pendingCandidatesToSend {
345-
select {
346-
case <-c.closed:
347-
return
348-
case c.localCandidateChannel <- pendingCandidate:
349-
}
350-
c.opts.Logger.Debug(context.Background(), "flushed buffered local candidate")
351-
}
352-
c.opts.Logger.Debug(context.Background(), "flushed buffered local candidates",
353-
slog.F("count", len(c.pendingCandidatesToSend)),
354-
)
355-
c.pendingCandidatesToSend = make([]webrtc.ICECandidateInit, 0)
356-
}()
357325
}
358326

359327
// AddRemoteCandidate adds a remote candidate to the RTC connection.
@@ -366,12 +334,12 @@ func (c *Conn) AddRemoteCandidate(i webrtc.ICECandidateInit) {
366334
go func() {
367335
c.negotiateMutex.Lock()
368336
defer c.negotiateMutex.Unlock()
369-
if c.isClosed() {
370-
return
371-
}
372337
c.opts.Logger.Debug(context.Background(), "accepting candidate", slog.F("length", len(i.Candidate)))
373338
err := c.rtc.AddICECandidate(i)
374339
if err != nil {
340+
if c.rtc.ConnectionState() == webrtc.PeerConnectionStateClosed {
341+
return
342+
}
375343
_ = c.CloseWithError(xerrors.Errorf("accept candidate: %w", err))
376344
}
377345
}()

0 commit comments

Comments
 (0)