Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 006ab67

Browse files
committed
Lock adding ICE candidate
1 parent b6003c7 commit 006ab67

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

peer/conn.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ func newWithClientOrServer(servers []webrtc.ICEServer, client bool, opts *ConnOp
8080
// of this will cause a connection failure.
8181
localCandidateChannel: make(chan webrtc.ICECandidateInit, 16),
8282
pendingCandidates: make([]webrtc.ICECandidateInit, 0),
83-
localSessionDescriptionChannel: make(chan webrtc.SessionDescription, 1),
84-
remoteSessionDescriptionChannel: make(chan webrtc.SessionDescription, 1),
83+
localSessionDescriptionChannel: make(chan webrtc.SessionDescription),
84+
remoteSessionDescriptionChannel: make(chan webrtc.SessionDescription),
8585
}
8686
if client {
8787
// If we're the client, we want to flip the echo and
@@ -357,10 +357,6 @@ func (c *Conn) negotiate() {
357357
return
358358
}
359359

360-
if c.offerrer {
361-
c.flushPendingCandidates()
362-
}
363-
364360
if !c.offerrer {
365361
answer, err := c.rtc.CreateAnswer(&webrtc.AnswerOptions{})
366362
if err != nil {
@@ -384,12 +380,8 @@ func (c *Conn) negotiate() {
384380
return
385381
case c.localSessionDescriptionChannel <- answer:
386382
}
387-
388-
c.flushPendingCandidates()
389383
}
390-
}
391384

392-
func (c *Conn) flushPendingCandidates() {
393385
c.pendingCandidatesMutex.Lock()
394386
defer c.pendingCandidatesMutex.Unlock()
395387
for _, pendingCandidate := range c.pendingCandidates {
@@ -421,6 +413,8 @@ func (c *Conn) AddRemoteCandidate(i webrtc.ICECandidateInit) error {
421413
slog.F("hash", c.hashCandidate(i)),
422414
slog.F("length", len(i.Candidate)),
423415
)
416+
c.closeMutex.Lock()
417+
defer c.closeMutex.Unlock()
424418
return c.rtc.AddICECandidate(i)
425419
}
426420

0 commit comments

Comments
 (0)