From b747cdb8222e6fe01c7d050a333a21823dc044d8 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Mon, 27 Dec 2021 23:43:30 -0800 Subject: [PATCH] Pass along mime type with TrackInfo (#292) --- pkg/rtc/uptrackmanager.go | 2 ++ test/client/client.go | 14 ++++++++++---- test/singlenode_test.go | 29 +++++++++++++++-------------- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/pkg/rtc/uptrackmanager.go b/pkg/rtc/uptrackmanager.go index 2f37549e4..ef848e5da 100644 --- a/pkg/rtc/uptrackmanager.go +++ b/pkg/rtc/uptrackmanager.go @@ -328,6 +328,8 @@ func (u *UptrackManager) MediaTrackReceived(track *webrtc.TrackRemote, rtpReceiv return } + ti.MimeType = track.Codec().MimeType + mt = NewMediaTrack(track, MediaTrackParams{ TrackInfo: ti, SignalCid: signalCid, diff --git a/test/client/client.go b/test/client/client.go index 390a781f4..6ad8acd3e 100644 --- a/test/client/client.go +++ b/test/client/client.go @@ -306,14 +306,14 @@ func (c *RTCClient) Run() error { return err } case *livekit.SignalResponse_Update: - participants := make(map[string]*livekit.ParticipantInfo) + c.lock.Lock() for _, p := range msg.Update.Participants { if p.State != livekit.ParticipantInfo_DISCONNECTED { - participants[p.Sid] = p + c.remoteParticipants[p.Sid] = p + } else { + delete(c.remoteParticipants, p.Sid) } } - c.lock.Lock() - c.remoteParticipants = participants c.lock.Unlock() case *livekit.SignalResponse_TrackPublished: @@ -389,6 +389,12 @@ func (c *RTCClient) RemoteParticipants() []*livekit.ParticipantInfo { return funk.Values(c.remoteParticipants).([]*livekit.ParticipantInfo) } +func (c *RTCClient) GetRemoteParticipant(sid string) *livekit.ParticipantInfo { + c.lock.Lock() + defer c.lock.Unlock() + return c.remoteParticipants[sid] +} + func (c *RTCClient) Stop() { logger.Infow("stopping client", "ID", c.ID()) _ = c.SendRequest(&livekit.SignalRequest{ diff --git a/test/singlenode_test.go b/test/singlenode_test.go index 526713d61..c847b5232 100644 --- a/test/singlenode_test.go +++ b/test/singlenode_test.go @@ -6,13 +6,14 @@ import ( "testing" "time" - "github.com/livekit/protocol/auth" - "github.com/pion/webrtc/v3" - "github.com/stretchr/testify/require" - "github.com/livekit/livekit-server/pkg/rtc" "github.com/livekit/livekit-server/pkg/testutils" testclient "github.com/livekit/livekit-server/test/client" + "github.com/livekit/protocol/auth" + "github.com/livekit/protocol/livekit" + "github.com/pion/webrtc/v3" + "github.com/stretchr/testify/require" + "github.com/thoas/go-funk" ) func TestClientCouldConnect(t *testing.T) { @@ -124,14 +125,14 @@ func TestSinglePublisher(t *testing.T) { waitUntilConnected(t, c1, c2) // publish a track and ensure clients receive it ok - t1, err := c1.AddStaticTrack("audio/opus", "audio", "webcam") + t1, err := c1.AddStaticTrack("audio/opus", "audio", "webcamaudio") require.NoError(t, err) defer t1.Stop() - t2, err := c1.AddStaticTrack("video/vp8", "video", "webcam") + t2, err := c1.AddStaticTrack("video/vp8", "video", "webcamvideo") require.NoError(t, err) defer t2.Stop() - success := testutils.WithTimeout(t, "c2 should receive two tracks", func() bool { + testutils.WithTimeout(t, "c2 should receive two tracks", func() bool { if len(c2.SubscribedTracks()) == 0 { return false } @@ -145,16 +146,19 @@ func TestSinglePublisher(t *testing.T) { require.Equal(t, c1.ID(), participantId) return true }) - if !success { - t.FailNow() - } + // ensure mime type is received + remoteC1 := c2.GetRemoteParticipant(c1.ID()) + audioTrack := funk.Find(remoteC1.Tracks, func(ti *livekit.TrackInfo) bool { + return ti.Name == "webcamaudio" + }).(*livekit.TrackInfo) + require.Equal(t, "audio/opus", audioTrack.MimeType) // a new client joins and should get the initial stream c3 := createRTCClient("c3", defaultServerPort, nil) // ensure that new client that has joined also received tracks waitUntilConnected(t, c3) - success = testutils.WithTimeout(t, "c3 should receive two tracks", func() bool { + testutils.WithTimeout(t, "c3 should receive two tracks", func() bool { if len(c3.SubscribedTracks()) == 0 { return false } @@ -164,9 +168,6 @@ 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()]