@@ -77,7 +77,6 @@ func newWithClientOrServer(servers []webrtc.ICEServer, client bool, opts *ConnOp
77
77
localCandidateChannel : make (chan webrtc.ICECandidateInit ),
78
78
localSessionDescriptionChannel : make (chan webrtc.SessionDescription ),
79
79
remoteSessionDescriptionChannel : make (chan webrtc.SessionDescription ),
80
- pendingCandidatesToSend : make ([]webrtc.ICECandidateInit , 0 ),
81
80
}
82
81
if client {
83
82
// If we're the client, we want to flip the echo and
@@ -129,9 +128,6 @@ type Conn struct {
129
128
130
129
negotiateMutex sync.Mutex
131
130
132
- pendingCandidatesToSend []webrtc.ICECandidateInit
133
- pendingCandidatesToSendMutex sync.Mutex
134
-
135
131
pingChannelID uint16
136
132
pingEchoChannelID uint16
137
133
@@ -227,16 +223,6 @@ func (c *Conn) init() error {
227
223
// Run this in a goroutine so we don't block pion/webrtc
228
224
// from continuing.
229
225
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
- }
240
226
c .opts .Logger .Debug (context .Background (), "sending local candidate" )
241
227
select {
242
228
case <- c .closed :
@@ -336,24 +322,6 @@ func (c *Conn) negotiate() {
336
322
}
337
323
c .opts .Logger .Debug (context .Background (), "sent answer" )
338
324
}
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
- }()
357
325
}
358
326
359
327
// AddRemoteCandidate adds a remote candidate to the RTC connection.
@@ -366,12 +334,12 @@ func (c *Conn) AddRemoteCandidate(i webrtc.ICECandidateInit) {
366
334
go func () {
367
335
c .negotiateMutex .Lock ()
368
336
defer c .negotiateMutex .Unlock ()
369
- if c .isClosed () {
370
- return
371
- }
372
337
c .opts .Logger .Debug (context .Background (), "accepting candidate" , slog .F ("length" , len (i .Candidate )))
373
338
err := c .rtc .AddICECandidate (i )
374
339
if err != nil {
340
+ if c .rtc .ConnectionState () == webrtc .PeerConnectionStateClosed {
341
+ return
342
+ }
375
343
_ = c .CloseWithError (xerrors .Errorf ("accept candidate: %w" , err ))
376
344
}
377
345
}()
0 commit comments