Skip to content

Commit

Permalink
Fix negotiation needed panic on nil Sendonly track
Browse files Browse the repository at this point in the history
In step 5.3.1, since we do not have a sender we can only choose
to signal that we need negotiation.
  • Loading branch information
edaniels authored and Sean-Der committed Mar 8, 2023
1 parent 6a520c9 commit 777e03c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
6 changes: 5 additions & 1 deletion peerconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,11 @@ func (pc *PeerConnection) checkNegotiationNeeded() bool { //nolint:gocognit
// Step 5.3.1
if t.Direction() == RTPTransceiverDirectionSendrecv || t.Direction() == RTPTransceiverDirectionSendonly {
descMsid, okMsid := m.Attribute(sdp.AttrKeyMsid)
track := t.Sender().Track()
sender := t.Sender()
if sender == nil {
return true
}
track := sender.Track()
if !okMsid || descMsid != track.StreamID()+" "+track.ID() {
return true
}
Expand Down
36 changes: 36 additions & 0 deletions peerconnection_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package webrtc

import (
"context"
"reflect"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -751,3 +752,38 @@ func TestTransportChain(t *testing.T) {

closePairNow(t, offer, answer)
}

func TestNegotiationNeededWithRecvonlyTrack(t *testing.T) {
lim := test.TimeOut(time.Second * 30)
defer lim.Stop()

report := test.CheckRoutines(t)
defer report()

pcOffer, pcAnswer, err := newPair()
if err != nil {
t.Fatal(err)
}

var wg sync.WaitGroup
wg.Add(1)
pcAnswer.OnNegotiationNeeded(wg.Done)

_, err = pcOffer.AddTransceiverFromKind(RTPCodecTypeVideo, RTPTransceiverInit{Direction: RTPTransceiverDirectionRecvonly})
if err != nil {
t.Fatal(err)
}

if err := signalPair(pcOffer, pcAnswer); err != nil {
t.Fatal(err)
}

onDataChannel, onDataChannelCancel := context.WithCancel(context.Background())
pcAnswer.OnDataChannel(func(d *DataChannel) {
onDataChannelCancel()
})
<-onDataChannel.Done()
wg.Wait()

closePairNow(t, pcOffer, pcAnswer)
}

0 comments on commit 777e03c

Please sign in to comment.