Skip to content

Commit 44566fd

Browse files
peer: fix crash in the rtcp handling (#67)
* peer: fix crash in the rtcp handling It turns out that a `receiver` may actually have a `nil` track inside. Not sure when and why but it looks like it happens during the negotiation (maybe when the transceiver exists, but the track does not exist already?). That's the body of the function: ```go func (r *RTPReceiver) Track() *TrackRemote { r.mu.RLock() defer r.mu.RUnlock() if len(r.tracks) != 1 { // so this is possible! return nil } return r.tracks[0].track } ``` * peer: more elegant handling of the nil in the rtcp Co-authored-by: Šimon Brandner <[email protected]> Co-authored-by: Šimon Brandner <[email protected]>
1 parent a4511dd commit 44566fd

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

pkg/peer/peer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func (p *Peer[ID]) WriteRTCP(trackID string, packets []RTCPPacketType) error {
135135
// Find the right track.
136136
receivers := p.peerConnection.GetReceivers()
137137
receiverIndex := slices.IndexFunc(receivers, func(receiver *webrtc.RTPReceiver) bool {
138-
return receiver.Track().ID() == trackID
138+
return receiver.Track() != nil && receiver.Track().ID() == trackID
139139
})
140140
if receiverIndex == -1 {
141141
return ErrTrackNotFound

0 commit comments

Comments
 (0)