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, "")
|
||||
|
||||
Reference in New Issue
Block a user