Admin APIs for participant management (#13)
* stubs for room admin APIs * room store APIs to persist participants * participant persistence * updated protobufs * implemented APIs to mute/remove/etc * fixed mute handling
This commit is contained in:
@@ -52,6 +52,63 @@ var (
|
||||
secretFlag,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "list-participants",
|
||||
Before: createClient,
|
||||
Action: listParticipants,
|
||||
Flags: []cli.Flag{
|
||||
roomFlag,
|
||||
roomHostFlag,
|
||||
apiKeyFlag,
|
||||
secretFlag,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "get-participant",
|
||||
Before: createClient,
|
||||
Action: getParticipant,
|
||||
Flags: []cli.Flag{
|
||||
roomFlag,
|
||||
identityFlag,
|
||||
roomHostFlag,
|
||||
apiKeyFlag,
|
||||
secretFlag,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "remove-participant",
|
||||
Before: createClient,
|
||||
Action: removeParticipant,
|
||||
Flags: []cli.Flag{
|
||||
roomFlag,
|
||||
identityFlag,
|
||||
roomHostFlag,
|
||||
apiKeyFlag,
|
||||
secretFlag,
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "mute-track",
|
||||
Before: createClient,
|
||||
Action: muteTrack,
|
||||
Flags: []cli.Flag{
|
||||
roomFlag,
|
||||
identityFlag,
|
||||
&cli.StringFlag{
|
||||
Name: "track",
|
||||
Usage: "track sid to mute",
|
||||
Required: true,
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "muted",
|
||||
Usage: "set to true to mute, false to unmute",
|
||||
Required: true,
|
||||
},
|
||||
roomHostFlag,
|
||||
apiKeyFlag,
|
||||
secretFlag,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
roomClient livekit.RoomService
|
||||
@@ -102,6 +159,75 @@ func deleteRoom(c *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func listParticipants(c *cli.Context) error {
|
||||
roomName := c.String("room")
|
||||
ctx := contextWithAccessToken(c, &auth.VideoGrant{RoomAdmin: true, Room: roomName})
|
||||
res, err := roomClient.ListParticipants(ctx, &livekit.ListParticipantsRequest{
|
||||
Room: roomName,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, p := range res.Participants {
|
||||
fmt.Printf("%s (%s)\t tracks: %d\n", p.Identity, p.State.String(), len(p.Tracks))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getParticipant(c *cli.Context) error {
|
||||
roomName := c.String("room")
|
||||
identity := c.String("identity")
|
||||
ctx := contextWithAccessToken(c, &auth.VideoGrant{RoomAdmin: true, Room: roomName})
|
||||
res, err := roomClient.GetParticipant(ctx, &livekit.RoomParticipantIdentity{
|
||||
Room: roomName,
|
||||
Identity: identity,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
PrintJSON(res)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func removeParticipant(c *cli.Context) error {
|
||||
roomName := c.String("room")
|
||||
identity := c.String("identity")
|
||||
ctx := contextWithAccessToken(c, &auth.VideoGrant{RoomAdmin: true, Room: roomName})
|
||||
_, err := roomClient.RemoveParticipant(ctx, &livekit.RoomParticipantIdentity{
|
||||
Room: roomName,
|
||||
Identity: identity,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println("successfully removed participant", identity)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func muteTrack(c *cli.Context) error {
|
||||
roomName := c.String("room")
|
||||
identity := c.String("identity")
|
||||
trackSid := c.String("track")
|
||||
ctx := contextWithAccessToken(c, &auth.VideoGrant{RoomAdmin: true, Room: roomName})
|
||||
_, err := roomClient.MutePublishedTrack(ctx, &livekit.MuteRoomTrackRequest{
|
||||
Room: roomName,
|
||||
Identity: identity,
|
||||
TrackSid: trackSid,
|
||||
Muted: c.Bool("muted"),
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Println("muted track", trackSid)
|
||||
return nil
|
||||
}
|
||||
|
||||
func contextWithAccessToken(c *cli.Context, grant *auth.VideoGrant) context.Context {
|
||||
ctx := context.Background()
|
||||
token, err := accessToken(c, grant, "")
|
||||
|
||||
@@ -20,15 +20,14 @@ var (
|
||||
Name: "join",
|
||||
Action: joinRoom,
|
||||
Flags: []cli.Flag{
|
||||
roomFlag,
|
||||
rtcHostFlag,
|
||||
&cli.StringFlag{
|
||||
Name: "token",
|
||||
Usage: "access token, not required in dev mode. if passed in, ignores --api-key, --api-secret, and --name",
|
||||
Usage: "access token, not required in dev mode. if passed in, ignores --api-key, --api-secret, and --identity",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "name",
|
||||
Usage: "name of participant",
|
||||
Name: "identity",
|
||||
Usage: "identity of the participant, required if token isn't passed in",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "audio",
|
||||
@@ -46,7 +45,7 @@ var (
|
||||
)
|
||||
|
||||
func joinRoom(c *cli.Context) error {
|
||||
name := c.String("name")
|
||||
identity := c.String("identity")
|
||||
roomId := c.String("room")
|
||||
token := c.String("token")
|
||||
|
||||
@@ -56,15 +55,15 @@ func joinRoom(c *cli.Context) error {
|
||||
if roomId == "" {
|
||||
return fmt.Errorf("--room is required")
|
||||
}
|
||||
if name == "" {
|
||||
return fmt.Errorf("--name is required")
|
||||
if identity == "" {
|
||||
return fmt.Errorf("--identity is required")
|
||||
}
|
||||
// token may be nil in dev mode
|
||||
var err error
|
||||
token, err = accessToken(c, &auth.VideoGrant{
|
||||
RoomJoin: true,
|
||||
Room: roomId,
|
||||
}, name)
|
||||
}, identity)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -15,8 +15,9 @@ import (
|
||||
|
||||
var (
|
||||
roomFlag = &cli.StringFlag{
|
||||
Name: "room",
|
||||
Usage: "name or id of the room",
|
||||
Name: "room",
|
||||
Usage: "name or id of the room",
|
||||
Required: true,
|
||||
}
|
||||
roomHostFlag = &cli.StringFlag{
|
||||
Name: "host",
|
||||
@@ -36,6 +37,11 @@ var (
|
||||
EnvVars: []string{"LIVEKIT_API_SECRET"},
|
||||
Required: true,
|
||||
}
|
||||
identityFlag = &cli.StringFlag{
|
||||
Name: "identity",
|
||||
Usage: "identity of participant",
|
||||
Required: true,
|
||||
}
|
||||
devFlag = &cli.BoolFlag{
|
||||
Name: "dev",
|
||||
Usage: "enables dev mode, longer expiration for tokens",
|
||||
|
||||
Reference in New Issue
Block a user