fix(sender): Don't write on closed channel
@@ -107,10 +107,15 @@ func (s *WebRTCSender) ReadRTCP() (rtcp.Packet, error) {
// WriteRTP to the track
func (s *WebRTCSender) WriteRTP(pkt *rtp.Packet) {
+ select {
+ case <-s.ctx.Done():
+ return
+ default:
s.mu.Lock()
defer s.mu.Unlock()
s.sendChan <- pkt
}
+}
// OnClose is called when the sender is closed
func (s *WebRTCSender) OnClose(f func()) {
