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:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/thoas/go-funk"
|
||||
"github.com/twitchtv/twirp"
|
||||
|
||||
"github.com/livekit/livekit-server/proto/livekit"
|
||||
@@ -64,3 +65,86 @@ func (s *RoomService) DeleteRoom(ctx context.Context, req *livekit.DeleteRoomReq
|
||||
res = &livekit.DeleteRoomResponse{}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *RoomService) ListParticipants(ctx context.Context, req *livekit.ListParticipantsRequest) (res *livekit.ListParticipantsResponse, err error) {
|
||||
if err = EnsureAdminPermission(ctx, req.Room); err != nil {
|
||||
return nil, twirpAuthError(err)
|
||||
}
|
||||
|
||||
participants, err := s.roomManager.roomStore.ListParticipants(req.Room)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
res = &livekit.ListParticipantsResponse{
|
||||
Participants: participants,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *RoomService) GetParticipant(ctx context.Context, req *livekit.RoomParticipantIdentity) (res *livekit.ParticipantInfo, err error) {
|
||||
if err = EnsureAdminPermission(ctx, req.Room); err != nil {
|
||||
return nil, twirpAuthError(err)
|
||||
}
|
||||
|
||||
participant, err := s.roomManager.roomStore.GetParticipant(req.Room, req.Identity)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
res = participant
|
||||
return
|
||||
}
|
||||
|
||||
func (s *RoomService) RemoveParticipant(ctx context.Context, req *livekit.RoomParticipantIdentity) (res *livekit.RemoveParticipantResponse, err error) {
|
||||
if err = EnsureAdminPermission(ctx, req.Room); err != nil {
|
||||
return nil, twirpAuthError(err)
|
||||
}
|
||||
|
||||
participant, err := s.roomManager.roomStore.GetParticipant(req.Room, req.Identity)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = s.roomManager.router.SendRTCMessage(req.Room, participant.Identity, &livekit.RTCNodeMessage{
|
||||
Message: &livekit.RTCNodeMessage_RemoveParticipant{
|
||||
RemoveParticipant: req,
|
||||
},
|
||||
})
|
||||
|
||||
res = &livekit.RemoveParticipantResponse{}
|
||||
return
|
||||
}
|
||||
|
||||
func (s *RoomService) MutePublishedTrack(ctx context.Context, req *livekit.MuteRoomTrackRequest) (res *livekit.MuteRoomTrackResponse, err error) {
|
||||
if err = EnsureAdminPermission(ctx, req.Room); err != nil {
|
||||
return nil, twirpAuthError(err)
|
||||
}
|
||||
|
||||
participant, err := s.roomManager.roomStore.GetParticipant(req.Room, req.Identity)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = s.roomManager.router.SendRTCMessage(req.Room, participant.Identity, &livekit.RTCNodeMessage{
|
||||
Message: &livekit.RTCNodeMessage_MuteTrack{
|
||||
MuteTrack: req,
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// find the track
|
||||
track := funk.Find(participant.Tracks, func(t *livekit.TrackInfo) bool {
|
||||
return t.Sid == req.TrackSid
|
||||
})
|
||||
if track == nil {
|
||||
return nil, twirp.NotFoundError(ErrTrackNotFound.Error())
|
||||
}
|
||||
res = &livekit.MuteRoomTrackResponse{
|
||||
Track: track.(*livekit.TrackInfo),
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user