Skip to content

Commit

Permalink
Adopt v2.0 APIs (#286)
Browse files Browse the repository at this point in the history
* Include SDK logs

* update to SDK 2.0

* update to v2

* 1.40
  • Loading branch information
davidzhao authored Feb 2, 2024
1 parent 5b690e3 commit a16f912
Show file tree
Hide file tree
Showing 18 changed files with 51 additions and 39 deletions.
2 changes: 1 addition & 1 deletion cmd/livekit-cli/egress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cmd/livekit-cli/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 3 additions & 6 deletions cmd/livekit-cli/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/livekit-cli/loadtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
18 changes: 13 additions & 5 deletions cmd/livekit-cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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...)
Expand Down
2 changes: 1 addition & 1 deletion cmd/livekit-cli/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion cmd/livekit-cli/sip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 4 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand All @@ -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=
Expand Down
11 changes: 11 additions & 0 deletions pkg/loadtester/loadtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"math/rand"
"net/url"
"os"
"sort"
"strings"
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions pkg/loadtester/loadtester.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/loadtester/speakersimulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/loadtester/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/h264looper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/looper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/opuslooper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion pkg/provider/vp8looper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
package livekitcli

const (
Version = "1.3.4"
Version = "1.4.0"
)

0 comments on commit a16f912

Please sign in to comment.