Skip to content

Commit

Permalink
Added allow-source to token creation, supports canPublishSources gran…
Browse files Browse the repository at this point in the history
…ts (#172)

* Added allow-source to token creation, supports canPublishSources grants

Version 1.2.5

* change help text

* also added --allow-update-metadata

* client side
  • Loading branch information
davidzhao authored Apr 21, 2023
1 parent 51ac604 commit 1b2e6d3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions cmd/livekit-cli/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/urfave/cli/v2"

"github.com/livekit/protocol/auth"
"github.com/livekit/protocol/livekit"
)

var (
Expand Down Expand Up @@ -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"},
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package livekitcli

const (
Version = "1.2.4"
Version = "1.2.5"
)

0 comments on commit 1b2e6d3

Please sign in to comment.