From a16f9123ca8f16946ff4a196b3b6fbb0d0144f2d Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 2 Feb 2024 14:28:02 -0800 Subject: [PATCH] Adopt v2.0 APIs (#286) * Include SDK logs * update to SDK 2.0 * update to v2 * 1.40 --- cmd/livekit-cli/egress.go | 2 +- cmd/livekit-cli/ingress.go | 2 +- cmd/livekit-cli/join.go | 9 +++------ cmd/livekit-cli/loadtest.go | 2 +- cmd/livekit-cli/main.go | 18 +++++++++++++----- cmd/livekit-cli/room.go | 2 +- cmd/livekit-cli/sip.go | 2 +- go.mod | 5 ++--- go.sum | 11 ++++------- pkg/loadtester/loadtest.go | 11 +++++++++++ pkg/loadtester/loadtester.go | 12 ++++++------ pkg/loadtester/speakersimulator.go | 2 +- pkg/loadtester/stats.go | 2 +- pkg/provider/h264looper.go | 2 +- pkg/provider/looper.go | 2 +- pkg/provider/opuslooper.go | 2 +- pkg/provider/vp8looper.go | 2 +- version.go | 2 +- 18 files changed, 51 insertions(+), 39 deletions(-) diff --git a/cmd/livekit-cli/egress.go b/cmd/livekit-cli/egress.go index 0f613531..712c8c49 100644 --- a/cmd/livekit-cli/egress.go +++ b/cmd/livekit-cli/egress.go @@ -33,7 +33,7 @@ import ( "github.com/livekit/livekit-cli/pkg/loadtester" "github.com/livekit/protocol/egress" "github.com/livekit/protocol/livekit" - lksdk "github.com/livekit/server-sdk-go" + lksdk "github.com/livekit/server-sdk-go/v2" ) const egressCategory = "Egress" diff --git a/cmd/livekit-cli/ingress.go b/cmd/livekit-cli/ingress.go index 933ee5ff..c185b8d0 100644 --- a/cmd/livekit-cli/ingress.go +++ b/cmd/livekit-cli/ingress.go @@ -24,7 +24,7 @@ import ( "google.golang.org/protobuf/encoding/protojson" "github.com/livekit/protocol/livekit" - lksdk "github.com/livekit/server-sdk-go" + lksdk "github.com/livekit/server-sdk-go/v2" ) const ingressCategory = "Ingress" diff --git a/cmd/livekit-cli/join.go b/cmd/livekit-cli/join.go index de9f5864..fe472db2 100644 --- a/cmd/livekit-cli/join.go +++ b/cmd/livekit-cli/join.go @@ -32,7 +32,7 @@ import ( provider2 "github.com/livekit/livekit-cli/pkg/provider" "github.com/livekit/protocol/livekit" "github.com/livekit/protocol/logger" - lksdk "github.com/livekit/server-sdk-go" + lksdk "github.com/livekit/server-sdk-go/v2" ) var ( @@ -79,11 +79,8 @@ func joinRoom(c *cli.Context) error { done := make(chan os.Signal, 1) roomCB := &lksdk.RoomCallback{ ParticipantCallback: lksdk.ParticipantCallback{ - OnDataReceived: func(data []byte, rp *lksdk.RemoteParticipant) { - identity := "" - if rp != nil { - identity = rp.Identity() - } + OnDataReceived: func(data []byte, params lksdk.DataReceiveParams) { + identity := params.SenderIdentity logger.Infow("received data", "data", data, "participant", identity) }, OnConnectionQualityChanged: func(update *livekit.ConnectionQualityInfo, p lksdk.Participant) { diff --git a/cmd/livekit-cli/loadtest.go b/cmd/livekit-cli/loadtest.go index 39ea97a7..939475c8 100644 --- a/cmd/livekit-cli/loadtest.go +++ b/cmd/livekit-cli/loadtest.go @@ -26,7 +26,7 @@ import ( "github.com/livekit/livekit-cli/pkg/loadtester" "github.com/livekit/protocol/logger" - lksdk "github.com/livekit/server-sdk-go" + lksdk "github.com/livekit/server-sdk-go/v2" ) var LoadTestCommands = []*cli.Command{ diff --git a/cmd/livekit-cli/main.go b/cmd/livekit-cli/main.go index 43870492..68f0c6e4 100644 --- a/cmd/livekit-cli/main.go +++ b/cmd/livekit-cli/main.go @@ -22,12 +22,10 @@ import ( livekitcli "github.com/livekit/livekit-cli" "github.com/livekit/protocol/logger" + lksdk "github.com/livekit/server-sdk-go/v2" ) func main() { - logConfig := &logger.Config{ - Level: "info", - } app := &cli.App{ Name: "livekit-cli", Usage: "CLI client to LiveKit", @@ -52,9 +50,19 @@ func main() { }, }, }, - } + Before: func(c *cli.Context) error { + logConfig := &logger.Config{ + Level: "info", + } + if c.Bool("verbose") { + logConfig.Level = "debug" + } + logger.InitFromConfig(logConfig, "livekit-cli") + lksdk.SetLogger(logger.GetLogger()) - logger.InitFromConfig(logConfig, "livekit-cli") + return nil + }, + } app.Commands = append(app.Commands, TokenCommands...) app.Commands = append(app.Commands, RoomCommands...) diff --git a/cmd/livekit-cli/room.go b/cmd/livekit-cli/room.go index 4285e970..5227b560 100644 --- a/cmd/livekit-cli/room.go +++ b/cmd/livekit-cli/room.go @@ -24,7 +24,7 @@ import ( "google.golang.org/protobuf/encoding/protojson" "github.com/livekit/protocol/livekit" - lksdk "github.com/livekit/server-sdk-go" + lksdk "github.com/livekit/server-sdk-go/v2" ) const roomCategory = "Room Server API" diff --git a/cmd/livekit-cli/sip.go b/cmd/livekit-cli/sip.go index 1af944f3..17a289e4 100644 --- a/cmd/livekit-cli/sip.go +++ b/cmd/livekit-cli/sip.go @@ -27,7 +27,7 @@ import ( "google.golang.org/protobuf/encoding/protojson" "github.com/livekit/protocol/livekit" - lksdk "github.com/livekit/server-sdk-go" + lksdk "github.com/livekit/server-sdk-go/v2" ) const sipCategory = "SIP" diff --git a/go.mod b/go.mod index 5bc8861d..fe141a1c 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,8 @@ require ( github.com/frostbyte73/core v0.0.9 github.com/ggwhite/go-masker v1.1.0 github.com/go-logr/logr v1.4.1 - github.com/livekit/protocol v1.9.5 - github.com/livekit/server-sdk-go v1.1.7 + github.com/livekit/protocol v1.9.7 + github.com/livekit/server-sdk-go/v2 v2.0.1 github.com/manifoldco/promptui v0.9.0 github.com/olekukonko/tablewriter v0.0.5 github.com/pion/rtcp v1.2.13 @@ -73,7 +73,6 @@ require ( github.com/prometheus/procfs v0.12.0 // indirect github.com/redis/go-redis/v9 v9.4.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect - github.com/thoas/go-funk v0.9.3 // indirect github.com/twitchtv/twirp v8.1.3+incompatible // indirect github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect github.com/zeebo/xxh3 v1.0.2 // indirect diff --git a/go.sum b/go.sum index dfc743cb..5c922f94 100644 --- a/go.sum +++ b/go.sum @@ -85,12 +85,12 @@ github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1 h1:jm09419p0lqTkD github.com/livekit/mageutil v0.0.0-20230125210925-54e8a70427c1/go.mod h1:Rs3MhFwutWhGwmY1VQsygw28z5bWcnEYmS1OG9OxjOQ= github.com/livekit/mediatransportutil v0.0.0-20231213075826-cccbf2b93d3f h1:XHrwGwLNGQB3ZqolH1YdMH/22hgXKr4vm+2M7JKMMGg= github.com/livekit/mediatransportutil v0.0.0-20231213075826-cccbf2b93d3f/go.mod h1:GBzn9xL+mivI1pW+tyExcKgbc0VOc29I9yJsNcAVaAc= -github.com/livekit/protocol v1.9.5 h1:/I6maM05euoUxrV6je16Qj5yCnCSPZ+nhHzm8akLCVk= -github.com/livekit/protocol v1.9.5/go.mod h1:daddOPw85C9nq6f9w1uiuc1i/He6X2gArlFcKUPELI4= +github.com/livekit/protocol v1.9.7 h1:5pYAMS/rzOStpIfRGnhXETPH/NyoFJtbV7FW4NHxg7o= +github.com/livekit/protocol v1.9.7/go.mod h1:daddOPw85C9nq6f9w1uiuc1i/He6X2gArlFcKUPELI4= github.com/livekit/psrpc v0.5.3-0.20231214055026-06ce27a934c9 h1:kXXV/NLVDHZ+Gn7xrR+UPpdwbH48n7WReBjLHAzqzhY= github.com/livekit/psrpc v0.5.3-0.20231214055026-06ce27a934c9/go.mod h1:cQjxg1oCxYHhxxv6KJH1gSvdtCHQoRZCHgPdm5N8v2g= -github.com/livekit/server-sdk-go v1.1.7 h1:fuNQgCpul4O32nJXRgeRRSSWuesubVfeOzzZ47ji2E8= -github.com/livekit/server-sdk-go v1.1.7/go.mod h1:bq1JRg0NpID0unZ0u66Ss0yU3777QqO0VQRWjQEKIck= +github.com/livekit/server-sdk-go/v2 v2.0.1 h1:qwuMK7WUd30DM7IJ2sOqpQcZcHqP02tzs5Y6CRsV4Lg= +github.com/livekit/server-sdk-go/v2 v2.0.1/go.mod h1:l9mRrCvR7H2AAJjs/624duhvuKUTjtVddjqiIQ6YcZw= github.com/mackerelio/go-osstat v0.2.4 h1:qxGbdPkFo65PXOb/F/nhDKpF2nGmGaCFDLXoZjJTtUs= github.com/mackerelio/go-osstat v0.2.4/go.mod h1:Zy+qzGdZs3A9cuIqmgbJvwbmLQH9dJvtio5ZjJTbdlQ= github.com/magefile/mage v1.15.0 h1:BvGheCMAsG3bWUDbZ8AyXXpCNwU9u5CB6sM+HNb9HYg= @@ -189,7 +189,6 @@ github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -198,8 +197,6 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= -github.com/thoas/go-funk v0.9.3 h1:7+nAEx3kn5ZJcnDm2Bh23N2yOtweO14bi//dvRtgLpw= -github.com/thoas/go-funk v0.9.3/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q= github.com/twitchtv/twirp v8.1.3+incompatible h1:+F4TdErPgSUbMZMwp13Q/KgDVuI7HJXP61mNV3/7iuU= github.com/twitchtv/twirp v8.1.3+incompatible/go.mod h1:RRJoFSAmTEh2weEqWtpPE3vFK5YBhA6bqp2l1kfCC5A= github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho= diff --git a/pkg/loadtester/loadtest.go b/pkg/loadtester/loadtest.go index c4b0217f..ad29a95f 100644 --- a/pkg/loadtester/loadtest.go +++ b/pkg/loadtester/loadtest.go @@ -18,6 +18,7 @@ import ( "context" "fmt" "math/rand" + "net/url" "os" "sort" "strings" @@ -71,6 +72,16 @@ func NewLoadTest(params Params) *LoadTest { } func (t *LoadTest) Run(ctx context.Context) error { + parsedUrl, err := url.Parse(t.Params.URL) + if err != nil { + return err + } + if strings.HasSuffix(parsedUrl.Hostname(), ".livekit.cloud") { + if t.Params.VideoPublishers > 50 || t.Params.Subscribers > 50 || t.Params.AudioPublishers > 50 { + return errors.New("Unable to perform load test on LiveKit Cloud. Load testing is prohibited by our acceptable use policy: https://livekit.io/legal/acceptable-use-policy") + } + } + stats, err := t.run(ctx, t.Params) if err != nil { return err diff --git a/pkg/loadtester/loadtester.go b/pkg/loadtester/loadtester.go index 6ac88c52..5620074d 100644 --- a/pkg/loadtester/loadtester.go +++ b/pkg/loadtester/loadtester.go @@ -26,8 +26,8 @@ import ( provider2 "github.com/livekit/livekit-cli/pkg/provider" "github.com/livekit/protocol/livekit" - lksdk "github.com/livekit/server-sdk-go" - "github.com/livekit/server-sdk-go/pkg/samplebuilder" + lksdk "github.com/livekit/server-sdk-go/v2" + "github.com/livekit/server-sdk-go/v2/pkg/samplebuilder" ) type LoadTester struct { @@ -104,7 +104,7 @@ func (t *LoadTester) Start() error { } identity := fmt.Sprintf("%s_%d", t.params.IdentityPrefix, t.params.Sequence) - t.room = lksdk.CreateRoom(&lksdk.RoomCallback{ + t.room = lksdk.NewRoom(&lksdk.RoomCallback{ ParticipantCallback: lksdk.ParticipantCallback{ OnTrackSubscribed: t.onTrackSubscribed, OnTrackSubscriptionFailed: func(sid string, rp *lksdk.RemoteParticipant) { @@ -132,8 +132,8 @@ func (t *LoadTester) Start() error { } t.running.Store(true) - for _, p := range t.room.GetParticipants() { - for _, pub := range p.Tracks() { + for _, p := range t.room.GetRemoteParticipants() { + for _, pub := range p.TrackPublications() { if remotePub, ok := pub.(*lksdk.RemoteTrackPublication); ok { t.onTrackPublished(remotePub, p) } @@ -302,7 +302,7 @@ func (t *LoadTester) onTrackSubscribed(track *webrtc.TrackRemote, pub *lksdk.Rem numTotal := 0 t.lock.Lock() for _, p := range t.subscribedParticipants { - tracks := p.Tracks() + tracks := p.TrackPublications() numTotal += len(tracks) for _, t := range tracks { if t.IsSubscribed() { diff --git a/pkg/loadtester/speakersimulator.go b/pkg/loadtester/speakersimulator.go index 0100fa72..92d205d7 100644 --- a/pkg/loadtester/speakersimulator.go +++ b/pkg/loadtester/speakersimulator.go @@ -20,7 +20,7 @@ import ( "github.com/frostbyte73/core" - lksdk "github.com/livekit/server-sdk-go" + lksdk "github.com/livekit/server-sdk-go/v2" ) type SpeakerSimulatorParams struct { diff --git a/pkg/loadtester/stats.go b/pkg/loadtester/stats.go index 4501950b..b09a2874 100644 --- a/pkg/loadtester/stats.go +++ b/pkg/loadtester/stats.go @@ -19,7 +19,7 @@ import ( "go.uber.org/atomic" - lksdk "github.com/livekit/server-sdk-go" + lksdk "github.com/livekit/server-sdk-go/v2" ) type testerStats struct { diff --git a/pkg/provider/h264looper.go b/pkg/provider/h264looper.go index 43be09eb..4a93b618 100644 --- a/pkg/provider/h264looper.go +++ b/pkg/provider/h264looper.go @@ -25,7 +25,7 @@ import ( "github.com/pion/webrtc/v3/pkg/media/h264reader" "github.com/livekit/protocol/livekit" - lksdk "github.com/livekit/server-sdk-go" + lksdk "github.com/livekit/server-sdk-go/v2" ) type H264VideoLooper struct { diff --git a/pkg/provider/looper.go b/pkg/provider/looper.go index 1a8cbfd7..fe4aafd9 100644 --- a/pkg/provider/looper.go +++ b/pkg/provider/looper.go @@ -18,7 +18,7 @@ import ( "github.com/pion/webrtc/v3" "github.com/livekit/protocol/livekit" - lksdk "github.com/livekit/server-sdk-go" + lksdk "github.com/livekit/server-sdk-go/v2" ) type Looper interface { diff --git a/pkg/provider/opuslooper.go b/pkg/provider/opuslooper.go index 71795abc..461e6757 100644 --- a/pkg/provider/opuslooper.go +++ b/pkg/provider/opuslooper.go @@ -24,7 +24,7 @@ import ( "github.com/pion/webrtc/v3/pkg/media" "github.com/pion/webrtc/v3/pkg/media/oggreader" - lksdk "github.com/livekit/server-sdk-go" + lksdk "github.com/livekit/server-sdk-go/v2" ) const ( diff --git a/pkg/provider/vp8looper.go b/pkg/provider/vp8looper.go index 6fddced9..21c2fdae 100644 --- a/pkg/provider/vp8looper.go +++ b/pkg/provider/vp8looper.go @@ -25,7 +25,7 @@ import ( "github.com/pion/webrtc/v3/pkg/media/ivfreader" "github.com/livekit/protocol/livekit" - lksdk "github.com/livekit/server-sdk-go" + lksdk "github.com/livekit/server-sdk-go/v2" ) type VP8VideoLooper struct { diff --git a/version.go b/version.go index 119556e2..5aa5ad2c 100644 --- a/version.go +++ b/version.go @@ -15,5 +15,5 @@ package livekitcli const ( - Version = "1.3.4" + Version = "1.4.0" )