Browse Source

make callbacks listen for ctx.Done() instead of co.closed

pull/3110/head
aler9 2 years ago
parent
commit
c8c5bf8188
  1. 13
      internal/protocols/webrtc/peer_connection.go
  2. 2
      internal/protocols/webrtc/whip_client.go

13
internal/protocols/webrtc/peer_connection.go

@ -36,7 +36,7 @@ type PeerConnection struct { @@ -36,7 +36,7 @@ type PeerConnection struct {
newLocalCandidate chan *webrtc.ICECandidateInit
connected chan struct{}
disconnected chan struct{}
closed chan struct{}
done chan struct{}
gatheringDone chan struct{}
incomingTrack chan trackRecvPair
@ -59,7 +59,7 @@ func (co *PeerConnection) Start() error { @@ -59,7 +59,7 @@ func (co *PeerConnection) Start() error {
co.newLocalCandidate = make(chan *webrtc.ICECandidateInit)
co.connected = make(chan struct{})
co.disconnected = make(chan struct{})
co.closed = make(chan struct{})
co.done = make(chan struct{})
co.gatheringDone = make(chan struct{})
co.incomingTrack = make(chan trackRecvPair)
@ -85,7 +85,7 @@ func (co *PeerConnection) Start() error { @@ -85,7 +85,7 @@ func (co *PeerConnection) Start() error {
co.wr.OnTrack(func(track *webrtc.TrackRemote, receiver *webrtc.RTPReceiver) {
select {
case co.incomingTrack <- trackRecvPair{track, receiver}:
case <-co.closed:
case <-co.ctx.Done():
}
})
}
@ -95,7 +95,7 @@ func (co *PeerConnection) Start() error { @@ -95,7 +95,7 @@ func (co *PeerConnection) Start() error {
defer co.stateChangeMutex.Unlock()
select {
case <-co.closed:
case <-co.done:
return
default:
}
@ -113,7 +113,7 @@ func (co *PeerConnection) Start() error { @@ -113,7 +113,7 @@ func (co *PeerConnection) Start() error {
close(co.disconnected)
case webrtc.PeerConnectionStateClosed:
close(co.closed)
close(co.done)
}
})
@ -123,7 +123,6 @@ func (co *PeerConnection) Start() error { @@ -123,7 +123,6 @@ func (co *PeerConnection) Start() error {
select {
case co.newLocalCandidate <- &v:
case <-co.connected:
case <-co.closed:
case <-co.ctx.Done():
}
} else {
@ -138,7 +137,7 @@ func (co *PeerConnection) Start() error { @@ -138,7 +137,7 @@ func (co *PeerConnection) Start() error {
func (co *PeerConnection) Close() {
co.ctxCancel()
co.wr.Close() //nolint:errcheck
<-co.closed
<-co.done
}
// CreatePartialOffer creates a partial offer.

2
internal/protocols/webrtc/whip_client.go

@ -89,7 +89,7 @@ outer: @@ -89,7 +89,7 @@ outer:
for {
select {
case ca := <-c.pc.NewLocalCandidate():
err := WHIPPatchCandidate(context.Background(), c.HTTPClient, c.URL.String(), offer, res.ETag, ca)
err := WHIPPatchCandidate(ctx, c.HTTPClient, c.URL.String(), offer, res.ETag, ca)
if err != nil {
c.pc.Close()
return nil, err

Loading…
Cancel
Save