From 1b2e6d35fac61c040d0896392f8819e0fb1cb5b1 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Thu, 20 Apr 2023 23:03:50 -0700 Subject: [PATCH] Added allow-source to token creation, supports canPublishSources grants (#172) * Added allow-source to token creation, supports canPublishSources grants Version 1.2.5 * change help text * also added --allow-update-metadata * client side --- cmd/livekit-cli/token.go | 33 +++++++++++++++++++++++++++++++++ version.go | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/cmd/livekit-cli/token.go b/cmd/livekit-cli/token.go index 81dde3fa..55042f01 100644 --- a/cmd/livekit-cli/token.go +++ b/cmd/livekit-cli/token.go @@ -9,6 +9,7 @@ import ( "github.com/urfave/cli/v2" "github.com/livekit/protocol/auth" + "github.com/livekit/protocol/livekit" ) var ( @@ -41,6 +42,14 @@ var ( Name: "recorder", Usage: "enable token to be used to record a room (requires --room)", }, + &cli.StringSliceFlag{ + Name: "allow-source", + Usage: "allow one or more sources to be published (i.e. --allow-source camera,microphone). if left blank, all sources are allowed", + }, + &cli.BoolFlag{ + Name: "allow-update-metadata", + Usage: "allow participant to update their own name and metadata from the client side", + }, &cli.StringFlag{ Name: "identity", Aliases: []string{"i"}, @@ -108,6 +117,30 @@ func createToken(c *cli.Context) error { grant.Recorder = true grant.Hidden = true } + if c.IsSet("allow-source") { + sourcesStr := c.StringSlice("allow-source") + sources := make([]livekit.TrackSource, 0, len(sourcesStr)) + for _, s := range sourcesStr { + var source livekit.TrackSource + switch s { + case "camera": + source = livekit.TrackSource_CAMERA + case "microphone": + source = livekit.TrackSource_MICROPHONE + case "screen_share": + source = livekit.TrackSource_SCREEN_SHARE + case "screen_share_audio": + source = livekit.TrackSource_SCREEN_SHARE_AUDIO + default: + return fmt.Errorf("invalid source: %s", s) + } + sources = append(sources, source) + } + grant.SetCanPublishSources(sources) + } + if c.Bool("allow-update-metadata") { + grant.SetCanUpdateOwnMetadata(true) + } if str := c.String("grant"); str != "" { if err := json.Unmarshal([]byte(str), grant); err != nil { diff --git a/version.go b/version.go index a3054272..315c007f 100644 --- a/version.go +++ b/version.go @@ -1,5 +1,5 @@ package livekitcli const ( - Version = "1.2.4" + Version = "1.2.5" )