fix(receiver): write on closed race condition
@@ -204,11 +204,16 @@ func (v *WebRTCVideoReceiver) ReadRTCP() (rtcp.Packet, error) {
// WriteRTCP write rtcp packet
func (v *WebRTCVideoReceiver) WriteRTCP(pkt rtcp.Packet) error {
+ select {
+ case <-v.ctx.Done():
+ return io.ErrClosedPipe
+ default:
v.mu.RLock()
v.rtcpCh <- pkt
v.mu.RUnlock()
return nil
}
+}
// Track returns receiver track
func (v *WebRTCVideoReceiver) Track() *webrtc.Track {
@@ -261,12 +266,13 @@ func (v *WebRTCVideoReceiver) receiveRTP() {
}
}
+ select {
+ case <-v.ctx.Done():
+ return
+ default:
v.mu.RLock()
v.rtpCh <- pkt
v.mu.RUnlock()
-
- if err != nil {
- log.Errorf("jb err => %v", err)
}
}
}
