Skip to content

Commit 59751f4

Browse files
committed
Remove buffer
1 parent aad88e0 commit 59751f4

File tree

1 file changed

+2
-37
lines changed

1 file changed

+2
-37
lines changed

peer/conn.go

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ func newWithClientOrServer(servers []webrtc.ICEServer, client bool, opts *ConnOp
7979
// This channel needs to be bufferred otherwise slow consumers
8080
// of this will cause a connection failure.
8181
localCandidateChannel: make(chan webrtc.ICECandidateInit, 16),
82-
pendingRemoteCandidates: make([]webrtc.ICECandidateInit, 0),
8382
localSessionDescriptionChannel: make(chan webrtc.SessionDescription, 1),
8483
remoteSessionDescriptionChannel: make(chan webrtc.SessionDescription, 1),
8584
}
@@ -129,10 +128,6 @@ type Conn struct {
129128
localSessionDescriptionChannel chan webrtc.SessionDescription
130129
remoteSessionDescriptionChannel chan webrtc.SessionDescription
131130

132-
pendingRemoteCandidates []webrtc.ICECandidateInit
133-
pendingCandidatesMutex sync.Mutex
134-
pendingCandidatesFlushed bool
135-
136131
pingChannelID uint16
137132
pingEchoChannelID uint16
138133

@@ -357,28 +352,6 @@ func (c *Conn) negotiate() {
357352
case c.localSessionDescriptionChannel <- answer:
358353
}
359354
}
360-
361-
// The ICE transport resets when the remote description is updated.
362-
// Adding ICE candidates before this point causes a failed connection,
363-
// because the candidate would be lost.
364-
c.pendingCandidatesMutex.Lock()
365-
defer c.pendingCandidatesMutex.Unlock()
366-
for _, pendingCandidate := range c.pendingRemoteCandidates {
367-
c.opts.Logger.Debug(context.Background(), "flushing buffered remote candidate",
368-
slog.F("hash", c.hashCandidate(pendingCandidate)),
369-
slog.F("length", len(pendingCandidate.Candidate)),
370-
)
371-
err := c.rtc.AddICECandidate(pendingCandidate)
372-
if err != nil {
373-
_ = c.CloseWithError(xerrors.Errorf("flush pending remote candidate: %w", err))
374-
return
375-
}
376-
}
377-
c.opts.Logger.Debug(context.Background(), "flushed buffered remote candidates",
378-
slog.F("count", len(c.pendingRemoteCandidates)),
379-
)
380-
c.pendingCandidatesFlushed = true
381-
c.pendingRemoteCandidates = make([]webrtc.ICECandidateInit, 0)
382355
}
383356

384357
// LocalCandidate returns a channel that emits when a local candidate
@@ -389,18 +362,10 @@ func (c *Conn) LocalCandidate() <-chan webrtc.ICECandidateInit {
389362

390363
// AddRemoteCandidate adds a remote candidate to the RTC connection.
391364
func (c *Conn) AddRemoteCandidate(i webrtc.ICECandidateInit) error {
392-
c.pendingCandidatesMutex.Lock()
393-
defer c.pendingCandidatesMutex.Unlock()
394-
fields := []slog.Field{
365+
c.opts.Logger.Debug(context.Background(), "adding remote candidate",
395366
slog.F("hash", c.hashCandidate(i)),
396367
slog.F("length", len(i.Candidate)),
397-
}
398-
if !c.pendingCandidatesFlushed {
399-
c.opts.Logger.Debug(context.Background(), "bufferring remote candidate", fields...)
400-
c.pendingRemoteCandidates = append(c.pendingRemoteCandidates, i)
401-
return nil
402-
}
403-
c.opts.Logger.Debug(context.Background(), "adding remote candidate", fields...)
368+
)
404369
return c.rtc.AddICECandidate(i)
405370
}
406371

0 commit comments

Comments
 (0)