From 61b9569e388cf98c3815c4fd7c3a23cf08716ce0 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Mon, 8 Feb 2021 16:35:14 -0800 Subject: [PATCH] fix: use track SID instead of source ID --- pkg/rtc/mediatrack.go | 2 +- test/singlenode_test.go | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/pkg/rtc/mediatrack.go b/pkg/rtc/mediatrack.go index f6c8234b9..8ce0bf169 100644 --- a/pkg/rtc/mediatrack.go +++ b/pkg/rtc/mediatrack.go @@ -241,7 +241,7 @@ func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.Tra defer t.lock.Unlock() if t.receiver == nil { // pack ID to identify all publishedTracks - packedId := PackTrackId(t.participantId, track.ID()) + packedId := PackTrackId(t.participantId, t.ID()) t.receiver = NewWrappedReceiver(sfu.NewWebRTCReceiver(receiver, track, t.participantId), packedId) t.receiver.SetRTCPCh(t.rtcpCh) t.receiver.OnCloseHandler(func() { diff --git a/test/singlenode_test.go b/test/singlenode_test.go index b83f27b53..b46824058 100644 --- a/test/singlenode_test.go +++ b/test/singlenode_test.go @@ -1,6 +1,7 @@ package test import ( + "strings" "testing" "github.com/stretchr/testify/assert" @@ -57,7 +58,7 @@ func TestSinglePublisher(t *testing.T) { // a new client joins and should get the initial stream c3 := createRTCClient("c3", defaultServerPort) - withTimeout(t, "c2 should receive two tracks", func() bool { + success := withTimeout(t, "c2 should receive two tracks", func() bool { if len(c2.SubscribedTracks()) == 0 { return false } @@ -70,10 +71,13 @@ func TestSinglePublisher(t *testing.T) { assert.Equal(t, "webcam", tr1.StreamID()) return true }) + if !success { + t.FailNow() + } // ensure that new client that has joined also received tracks waitUntilConnected(t, c3) - withTimeout(t, "c2 should receive two tracks", func() bool { + success = withTimeout(t, "c2 should receive two tracks", func() bool { if len(c3.SubscribedTracks()) == 0 { return false } @@ -83,4 +87,13 @@ func TestSinglePublisher(t *testing.T) { } return true }) + if !success { + t.FailNow() + } + + // ensure that the track ids are generated by server + tracks := c3.SubscribedTracks()[c1.ID()] + for _, tr := range tracks { + assert.True(t, strings.Contains(tr.ID(), "|TR_"), "track should begin with TR") + } }