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:
@@ -103,6 +103,19 @@ func EnsureJoinPermission(ctx context.Context) (name string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func EnsureAdminPermission(ctx context.Context, room string) error {
|
||||
claims := GetGrants(ctx)
|
||||
if claims == nil || claims.Video == nil {
|
||||
return ErrPermissionDenied
|
||||
}
|
||||
|
||||
if !claims.Video.RoomAdmin || room != claims.Video.Room {
|
||||
return ErrPermissionDenied
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func EnsureCreatePermission(ctx context.Context) error {
|
||||
claims := GetGrants(ctx)
|
||||
if claims == nil {
|
||||
|
||||
@@ -3,5 +3,7 @@ package service
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
ErrRoomNotFound = errors.New("requested room does not exist")
|
||||
ErrRoomNotFound = errors.New("requested room does not exist")
|
||||
ErrParticipantNotFound = errors.New("participant does not exist")
|
||||
ErrTrackNotFound = errors.New("track is not found")
|
||||
)
|
||||
|
||||
@@ -15,14 +15,17 @@ type LocalRoomStore struct {
|
||||
rooms map[string]*livekit.Room
|
||||
// map of roomName => roomId
|
||||
roomIds map[string]string
|
||||
lock sync.RWMutex
|
||||
// map of roomName => { identity: participant }
|
||||
participants map[string]map[string]*livekit.ParticipantInfo
|
||||
lock sync.RWMutex
|
||||
}
|
||||
|
||||
func NewLocalRoomStore() *LocalRoomStore {
|
||||
return &LocalRoomStore{
|
||||
rooms: make(map[string]*livekit.Room),
|
||||
roomIds: make(map[string]string),
|
||||
lock: sync.RWMutex{},
|
||||
rooms: make(map[string]*livekit.Room),
|
||||
roomIds: make(map[string]string),
|
||||
participants: make(map[string]map[string]*livekit.ParticipantInfo),
|
||||
lock: sync.RWMutex{},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +72,62 @@ func (p *LocalRoomStore) DeleteRoom(idOrName string) error {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
|
||||
delete(p.rooms, room.Sid)
|
||||
delete(p.participants, room.Name)
|
||||
delete(p.roomIds, room.Name)
|
||||
delete(p.rooms, room.Sid)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) PersistParticipant(roomName string, participant *livekit.ParticipantInfo) error {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
roomParticipants := p.participants[roomName]
|
||||
if roomParticipants == nil {
|
||||
roomParticipants = make(map[string]*livekit.ParticipantInfo)
|
||||
p.participants[roomName] = roomParticipants
|
||||
}
|
||||
roomParticipants[participant.Identity] = participant
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) GetParticipant(roomName, identity string) (*livekit.ParticipantInfo, error) {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
|
||||
roomParticipants := p.participants[roomName]
|
||||
if roomParticipants == nil {
|
||||
return nil, ErrParticipantNotFound
|
||||
}
|
||||
participant := roomParticipants[identity]
|
||||
if participant == nil {
|
||||
return nil, ErrParticipantNotFound
|
||||
}
|
||||
return participant, nil
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) ListParticipants(roomName string) ([]*livekit.ParticipantInfo, error) {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
|
||||
roomParticipants := p.participants[roomName]
|
||||
if roomParticipants == nil {
|
||||
// empty array
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
items := funk.Values(roomParticipants).([]*livekit.ParticipantInfo)
|
||||
// TODO: should short this to something reasonable
|
||||
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) DeleteParticipant(roomName, identity string) error {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
|
||||
roomParticipants := p.participants[roomName]
|
||||
if roomParticipants != nil {
|
||||
delete(roomParticipants, identity)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -17,12 +17,12 @@ const (
|
||||
|
||||
// hash of room_id => room name
|
||||
RoomIdMap = "room_id_map"
|
||||
//
|
||||
//// hash of participant_name => participant_id
|
||||
//// a key for each room, with expiration
|
||||
//RoomParticipantMapPrefix = "participant_map:room:"
|
||||
//
|
||||
//participantMappingTTL = 24 * time.Hour
|
||||
|
||||
// hash of participant_name => ParticipantInfo
|
||||
// a key for each room, with expiration
|
||||
RoomParticipantsPrefix = "room_participants:"
|
||||
|
||||
participantMappingTTL = 24 * time.Hour
|
||||
)
|
||||
|
||||
type RedisRoomStore struct {
|
||||
@@ -102,16 +102,77 @@ func (p *RedisRoomStore) ListRooms() ([]*livekit.Room, error) {
|
||||
|
||||
func (p *RedisRoomStore) DeleteRoom(idOrName string) error {
|
||||
room, err := p.GetRoom(idOrName)
|
||||
var sid, name string
|
||||
|
||||
if err == ErrRoomNotFound {
|
||||
return nil
|
||||
} else if err != nil {
|
||||
// try to clean up as best as we could
|
||||
sid = idOrName
|
||||
name = idOrName
|
||||
} else if err == nil {
|
||||
sid = room.Sid
|
||||
name = room.Name
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
|
||||
pp := p.rc.Pipeline()
|
||||
pp.HDel(p.ctx, RoomIdMap, room.Sid)
|
||||
pp.HDel(p.ctx, RoomsKey, room.Name)
|
||||
pp.HDel(p.ctx, RoomIdMap, sid)
|
||||
pp.HDel(p.ctx, RoomsKey, name)
|
||||
pp.Del(p.ctx, RoomParticipantsPrefix+name)
|
||||
|
||||
_, err = pp.Exec(p.ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *RedisRoomStore) PersistParticipant(roomName string, participant *livekit.ParticipantInfo) error {
|
||||
key := RoomParticipantsPrefix + roomName
|
||||
|
||||
data, err := proto.Marshal(participant)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return p.rc.HSet(p.ctx, key, participant.Identity, data).Err()
|
||||
}
|
||||
|
||||
func (p *RedisRoomStore) GetParticipant(roomName, identity string) (*livekit.ParticipantInfo, error) {
|
||||
key := RoomParticipantsPrefix + roomName
|
||||
data, err := p.rc.HGet(p.ctx, key, identity).Result()
|
||||
if err == redis.Nil {
|
||||
return nil, ErrParticipantNotFound
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
pi := livekit.ParticipantInfo{}
|
||||
if err := proto.Unmarshal([]byte(data), &pi); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &pi, nil
|
||||
}
|
||||
|
||||
func (p *RedisRoomStore) ListParticipants(roomName string) ([]*livekit.ParticipantInfo, error) {
|
||||
key := RoomParticipantsPrefix + roomName
|
||||
items, err := p.rc.HVals(p.ctx, key).Result()
|
||||
if err == redis.Nil {
|
||||
return nil, nil
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
participants := make([]*livekit.ParticipantInfo, 0, len(items))
|
||||
for _, item := range items {
|
||||
pi := livekit.ParticipantInfo{}
|
||||
if err := proto.Unmarshal([]byte(item), &pi); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
participants = append(participants, &pi)
|
||||
}
|
||||
return participants, nil
|
||||
}
|
||||
|
||||
func (p *RedisRoomStore) DeleteParticipant(roomName, identity string) error {
|
||||
key := RoomParticipantsPrefix + roomName
|
||||
|
||||
return p.rc.HDel(p.ctx, key, identity).Err()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package service_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/service"
|
||||
"github.com/livekit/livekit-server/proto/livekit"
|
||||
)
|
||||
|
||||
func TestParticipantPersisence(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
return
|
||||
}
|
||||
rs := service.NewRedisRoomStore(redisClient())
|
||||
|
||||
roomName := "room1"
|
||||
rs.DeleteRoom(roomName)
|
||||
|
||||
p := &livekit.ParticipantInfo{
|
||||
Sid: "PA_test",
|
||||
Identity: "test",
|
||||
State: livekit.ParticipantInfo_ACTIVE,
|
||||
Tracks: []*livekit.TrackInfo{
|
||||
{
|
||||
Sid: "track1",
|
||||
Type: livekit.TrackType_AUDIO,
|
||||
Name: "audio",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// create the participant
|
||||
assert.NoError(t, rs.PersistParticipant(roomName, p))
|
||||
|
||||
// result should match
|
||||
pGet, err := rs.GetParticipant(roomName, p.Identity)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, p.Identity, pGet.Identity)
|
||||
assert.Equal(t, len(p.Tracks), len(pGet.Tracks))
|
||||
assert.Equal(t, p.Tracks[0].Sid, pGet.Tracks[0].Sid)
|
||||
|
||||
// list should return one participant
|
||||
participants, err := rs.ListParticipants(roomName)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, participants, 1)
|
||||
|
||||
// deleting participant should return back to normal
|
||||
assert.NoError(t, rs.DeleteParticipant(roomName, p.Identity))
|
||||
|
||||
participants, err = rs.ListParticipants(roomName)
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, participants, 0)
|
||||
|
||||
// shouldn't be able to get it
|
||||
_, err = rs.GetParticipant(roomName, p.Identity)
|
||||
assert.Equal(t, err, service.ErrParticipantNotFound)
|
||||
}
|
||||
@@ -218,6 +218,13 @@ func (r *RoomManager) getOrCreateRoom(roomName string) (*rtc.Room, error) {
|
||||
logger.Errorw("could not delete room", "error", err)
|
||||
}
|
||||
})
|
||||
room.OnParticipantChanged(func(p types.Participant) {
|
||||
if p.State() == livekit.ParticipantInfo_DISCONNECTED {
|
||||
r.roomStore.DeleteParticipant(roomName, p.Identity())
|
||||
} else {
|
||||
r.roomStore.PersistParticipant(roomName, p.ToProto())
|
||||
}
|
||||
})
|
||||
r.lock.Lock()
|
||||
r.rooms[roomName] = room
|
||||
r.lock.Unlock()
|
||||
@@ -296,3 +303,29 @@ func (r *RoomManager) rtcSessionWorker(room *rtc.Room, participant types.Partici
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RoomManager) handleRTCMessage(roomName, identity string, msg *livekit.RTCNodeMessage) {
|
||||
r.lock.RLock()
|
||||
room := r.rooms[roomName]
|
||||
r.lock.RUnlock()
|
||||
|
||||
if room == nil {
|
||||
logger.Warnw("Could not find room", "room", roomName)
|
||||
return
|
||||
}
|
||||
|
||||
participant := room.GetParticipant(identity)
|
||||
if participant == nil {
|
||||
return
|
||||
}
|
||||
|
||||
switch rm := msg.Message.(type) {
|
||||
case *livekit.RTCNodeMessage_RemoveParticipant:
|
||||
logger.Infow("removing participant", "room", roomName, "participant", identity)
|
||||
room.RemoveParticipant(identity)
|
||||
case *livekit.RTCNodeMessage_MuteTrack:
|
||||
logger.Debugw("setting track muted", "room", roomName, "participant", identity,
|
||||
"track", rm.MuteTrack.TrackSid, "muted", rm.MuteTrack.Muted)
|
||||
participant.SetTrackMuted(rm.MuteTrack.TrackSid, rm.MuteTrack.Muted)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -14,4 +14,9 @@ type RoomStore interface {
|
||||
GetRoom(idOrName string) (*livekit.Room, error)
|
||||
ListRooms() ([]*livekit.Room, error)
|
||||
DeleteRoom(idOrName string) error
|
||||
|
||||
PersistParticipant(roomName string, participant *livekit.ParticipantInfo) error
|
||||
GetParticipant(roomName, identity string) (*livekit.ParticipantInfo, error)
|
||||
ListParticipants(roomName string) ([]*livekit.ParticipantInfo, error)
|
||||
DeleteParticipant(roomName, identity string) error
|
||||
}
|
||||
|
||||
@@ -67,6 +67,7 @@ func NewLivekitServer(conf *config.Config,
|
||||
|
||||
// hook up router to the RoomManager
|
||||
router.OnNewParticipantRTC(roomManager.StartSession)
|
||||
router.OnRTCMessage(roomManager.handleRTCMessage)
|
||||
|
||||
// clean up old rooms on startup
|
||||
if err = roomManager.CleanupRooms(); err != nil {
|
||||
|
||||
@@ -20,6 +20,18 @@ type FakeRoomStore struct {
|
||||
createRoomReturnsOnCall map[int]struct {
|
||||
result1 error
|
||||
}
|
||||
DeleteParticipantStub func(string, string) error
|
||||
deleteParticipantMutex sync.RWMutex
|
||||
deleteParticipantArgsForCall []struct {
|
||||
arg1 string
|
||||
arg2 string
|
||||
}
|
||||
deleteParticipantReturns struct {
|
||||
result1 error
|
||||
}
|
||||
deleteParticipantReturnsOnCall map[int]struct {
|
||||
result1 error
|
||||
}
|
||||
DeleteRoomStub func(string) error
|
||||
deleteRoomMutex sync.RWMutex
|
||||
deleteRoomArgsForCall []struct {
|
||||
@@ -31,6 +43,20 @@ type FakeRoomStore struct {
|
||||
deleteRoomReturnsOnCall map[int]struct {
|
||||
result1 error
|
||||
}
|
||||
GetParticipantStub func(string, string) (*livekit.ParticipantInfo, error)
|
||||
getParticipantMutex sync.RWMutex
|
||||
getParticipantArgsForCall []struct {
|
||||
arg1 string
|
||||
arg2 string
|
||||
}
|
||||
getParticipantReturns struct {
|
||||
result1 *livekit.ParticipantInfo
|
||||
result2 error
|
||||
}
|
||||
getParticipantReturnsOnCall map[int]struct {
|
||||
result1 *livekit.ParticipantInfo
|
||||
result2 error
|
||||
}
|
||||
GetRoomStub func(string) (*livekit.Room, error)
|
||||
getRoomMutex sync.RWMutex
|
||||
getRoomArgsForCall []struct {
|
||||
@@ -44,6 +70,19 @@ type FakeRoomStore struct {
|
||||
result1 *livekit.Room
|
||||
result2 error
|
||||
}
|
||||
ListParticipantsStub func(string) ([]*livekit.ParticipantInfo, error)
|
||||
listParticipantsMutex sync.RWMutex
|
||||
listParticipantsArgsForCall []struct {
|
||||
arg1 string
|
||||
}
|
||||
listParticipantsReturns struct {
|
||||
result1 []*livekit.ParticipantInfo
|
||||
result2 error
|
||||
}
|
||||
listParticipantsReturnsOnCall map[int]struct {
|
||||
result1 []*livekit.ParticipantInfo
|
||||
result2 error
|
||||
}
|
||||
ListRoomsStub func() ([]*livekit.Room, error)
|
||||
listRoomsMutex sync.RWMutex
|
||||
listRoomsArgsForCall []struct {
|
||||
@@ -56,6 +95,18 @@ type FakeRoomStore struct {
|
||||
result1 []*livekit.Room
|
||||
result2 error
|
||||
}
|
||||
PersistParticipantStub func(string, *livekit.ParticipantInfo) error
|
||||
persistParticipantMutex sync.RWMutex
|
||||
persistParticipantArgsForCall []struct {
|
||||
arg1 string
|
||||
arg2 *livekit.ParticipantInfo
|
||||
}
|
||||
persistParticipantReturns struct {
|
||||
result1 error
|
||||
}
|
||||
persistParticipantReturnsOnCall map[int]struct {
|
||||
result1 error
|
||||
}
|
||||
invocations map[string][][]interface{}
|
||||
invocationsMutex sync.RWMutex
|
||||
}
|
||||
@@ -121,6 +172,68 @@ func (fake *FakeRoomStore) CreateRoomReturnsOnCall(i int, result1 error) {
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) DeleteParticipant(arg1 string, arg2 string) error {
|
||||
fake.deleteParticipantMutex.Lock()
|
||||
ret, specificReturn := fake.deleteParticipantReturnsOnCall[len(fake.deleteParticipantArgsForCall)]
|
||||
fake.deleteParticipantArgsForCall = append(fake.deleteParticipantArgsForCall, struct {
|
||||
arg1 string
|
||||
arg2 string
|
||||
}{arg1, arg2})
|
||||
stub := fake.DeleteParticipantStub
|
||||
fakeReturns := fake.deleteParticipantReturns
|
||||
fake.recordInvocation("DeleteParticipant", []interface{}{arg1, arg2})
|
||||
fake.deleteParticipantMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub(arg1, arg2)
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) DeleteParticipantCallCount() int {
|
||||
fake.deleteParticipantMutex.RLock()
|
||||
defer fake.deleteParticipantMutex.RUnlock()
|
||||
return len(fake.deleteParticipantArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) DeleteParticipantCalls(stub func(string, string) error) {
|
||||
fake.deleteParticipantMutex.Lock()
|
||||
defer fake.deleteParticipantMutex.Unlock()
|
||||
fake.DeleteParticipantStub = stub
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) DeleteParticipantArgsForCall(i int) (string, string) {
|
||||
fake.deleteParticipantMutex.RLock()
|
||||
defer fake.deleteParticipantMutex.RUnlock()
|
||||
argsForCall := fake.deleteParticipantArgsForCall[i]
|
||||
return argsForCall.arg1, argsForCall.arg2
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) DeleteParticipantReturns(result1 error) {
|
||||
fake.deleteParticipantMutex.Lock()
|
||||
defer fake.deleteParticipantMutex.Unlock()
|
||||
fake.DeleteParticipantStub = nil
|
||||
fake.deleteParticipantReturns = struct {
|
||||
result1 error
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) DeleteParticipantReturnsOnCall(i int, result1 error) {
|
||||
fake.deleteParticipantMutex.Lock()
|
||||
defer fake.deleteParticipantMutex.Unlock()
|
||||
fake.DeleteParticipantStub = nil
|
||||
if fake.deleteParticipantReturnsOnCall == nil {
|
||||
fake.deleteParticipantReturnsOnCall = make(map[int]struct {
|
||||
result1 error
|
||||
})
|
||||
}
|
||||
fake.deleteParticipantReturnsOnCall[i] = struct {
|
||||
result1 error
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) DeleteRoom(arg1 string) error {
|
||||
fake.deleteRoomMutex.Lock()
|
||||
ret, specificReturn := fake.deleteRoomReturnsOnCall[len(fake.deleteRoomArgsForCall)]
|
||||
@@ -182,6 +295,71 @@ func (fake *FakeRoomStore) DeleteRoomReturnsOnCall(i int, result1 error) {
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) GetParticipant(arg1 string, arg2 string) (*livekit.ParticipantInfo, error) {
|
||||
fake.getParticipantMutex.Lock()
|
||||
ret, specificReturn := fake.getParticipantReturnsOnCall[len(fake.getParticipantArgsForCall)]
|
||||
fake.getParticipantArgsForCall = append(fake.getParticipantArgsForCall, struct {
|
||||
arg1 string
|
||||
arg2 string
|
||||
}{arg1, arg2})
|
||||
stub := fake.GetParticipantStub
|
||||
fakeReturns := fake.getParticipantReturns
|
||||
fake.recordInvocation("GetParticipant", []interface{}{arg1, arg2})
|
||||
fake.getParticipantMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub(arg1, arg2)
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1, ret.result2
|
||||
}
|
||||
return fakeReturns.result1, fakeReturns.result2
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) GetParticipantCallCount() int {
|
||||
fake.getParticipantMutex.RLock()
|
||||
defer fake.getParticipantMutex.RUnlock()
|
||||
return len(fake.getParticipantArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) GetParticipantCalls(stub func(string, string) (*livekit.ParticipantInfo, error)) {
|
||||
fake.getParticipantMutex.Lock()
|
||||
defer fake.getParticipantMutex.Unlock()
|
||||
fake.GetParticipantStub = stub
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) GetParticipantArgsForCall(i int) (string, string) {
|
||||
fake.getParticipantMutex.RLock()
|
||||
defer fake.getParticipantMutex.RUnlock()
|
||||
argsForCall := fake.getParticipantArgsForCall[i]
|
||||
return argsForCall.arg1, argsForCall.arg2
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) GetParticipantReturns(result1 *livekit.ParticipantInfo, result2 error) {
|
||||
fake.getParticipantMutex.Lock()
|
||||
defer fake.getParticipantMutex.Unlock()
|
||||
fake.GetParticipantStub = nil
|
||||
fake.getParticipantReturns = struct {
|
||||
result1 *livekit.ParticipantInfo
|
||||
result2 error
|
||||
}{result1, result2}
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) GetParticipantReturnsOnCall(i int, result1 *livekit.ParticipantInfo, result2 error) {
|
||||
fake.getParticipantMutex.Lock()
|
||||
defer fake.getParticipantMutex.Unlock()
|
||||
fake.GetParticipantStub = nil
|
||||
if fake.getParticipantReturnsOnCall == nil {
|
||||
fake.getParticipantReturnsOnCall = make(map[int]struct {
|
||||
result1 *livekit.ParticipantInfo
|
||||
result2 error
|
||||
})
|
||||
}
|
||||
fake.getParticipantReturnsOnCall[i] = struct {
|
||||
result1 *livekit.ParticipantInfo
|
||||
result2 error
|
||||
}{result1, result2}
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) GetRoom(arg1 string) (*livekit.Room, error) {
|
||||
fake.getRoomMutex.Lock()
|
||||
ret, specificReturn := fake.getRoomReturnsOnCall[len(fake.getRoomArgsForCall)]
|
||||
@@ -246,6 +424,70 @@ func (fake *FakeRoomStore) GetRoomReturnsOnCall(i int, result1 *livekit.Room, re
|
||||
}{result1, result2}
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) ListParticipants(arg1 string) ([]*livekit.ParticipantInfo, error) {
|
||||
fake.listParticipantsMutex.Lock()
|
||||
ret, specificReturn := fake.listParticipantsReturnsOnCall[len(fake.listParticipantsArgsForCall)]
|
||||
fake.listParticipantsArgsForCall = append(fake.listParticipantsArgsForCall, struct {
|
||||
arg1 string
|
||||
}{arg1})
|
||||
stub := fake.ListParticipantsStub
|
||||
fakeReturns := fake.listParticipantsReturns
|
||||
fake.recordInvocation("ListParticipants", []interface{}{arg1})
|
||||
fake.listParticipantsMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub(arg1)
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1, ret.result2
|
||||
}
|
||||
return fakeReturns.result1, fakeReturns.result2
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) ListParticipantsCallCount() int {
|
||||
fake.listParticipantsMutex.RLock()
|
||||
defer fake.listParticipantsMutex.RUnlock()
|
||||
return len(fake.listParticipantsArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) ListParticipantsCalls(stub func(string) ([]*livekit.ParticipantInfo, error)) {
|
||||
fake.listParticipantsMutex.Lock()
|
||||
defer fake.listParticipantsMutex.Unlock()
|
||||
fake.ListParticipantsStub = stub
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) ListParticipantsArgsForCall(i int) string {
|
||||
fake.listParticipantsMutex.RLock()
|
||||
defer fake.listParticipantsMutex.RUnlock()
|
||||
argsForCall := fake.listParticipantsArgsForCall[i]
|
||||
return argsForCall.arg1
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) ListParticipantsReturns(result1 []*livekit.ParticipantInfo, result2 error) {
|
||||
fake.listParticipantsMutex.Lock()
|
||||
defer fake.listParticipantsMutex.Unlock()
|
||||
fake.ListParticipantsStub = nil
|
||||
fake.listParticipantsReturns = struct {
|
||||
result1 []*livekit.ParticipantInfo
|
||||
result2 error
|
||||
}{result1, result2}
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) ListParticipantsReturnsOnCall(i int, result1 []*livekit.ParticipantInfo, result2 error) {
|
||||
fake.listParticipantsMutex.Lock()
|
||||
defer fake.listParticipantsMutex.Unlock()
|
||||
fake.ListParticipantsStub = nil
|
||||
if fake.listParticipantsReturnsOnCall == nil {
|
||||
fake.listParticipantsReturnsOnCall = make(map[int]struct {
|
||||
result1 []*livekit.ParticipantInfo
|
||||
result2 error
|
||||
})
|
||||
}
|
||||
fake.listParticipantsReturnsOnCall[i] = struct {
|
||||
result1 []*livekit.ParticipantInfo
|
||||
result2 error
|
||||
}{result1, result2}
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) ListRooms() ([]*livekit.Room, error) {
|
||||
fake.listRoomsMutex.Lock()
|
||||
ret, specificReturn := fake.listRoomsReturnsOnCall[len(fake.listRoomsArgsForCall)]
|
||||
@@ -302,17 +544,87 @@ func (fake *FakeRoomStore) ListRoomsReturnsOnCall(i int, result1 []*livekit.Room
|
||||
}{result1, result2}
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) PersistParticipant(arg1 string, arg2 *livekit.ParticipantInfo) error {
|
||||
fake.persistParticipantMutex.Lock()
|
||||
ret, specificReturn := fake.persistParticipantReturnsOnCall[len(fake.persistParticipantArgsForCall)]
|
||||
fake.persistParticipantArgsForCall = append(fake.persistParticipantArgsForCall, struct {
|
||||
arg1 string
|
||||
arg2 *livekit.ParticipantInfo
|
||||
}{arg1, arg2})
|
||||
stub := fake.PersistParticipantStub
|
||||
fakeReturns := fake.persistParticipantReturns
|
||||
fake.recordInvocation("PersistParticipant", []interface{}{arg1, arg2})
|
||||
fake.persistParticipantMutex.Unlock()
|
||||
if stub != nil {
|
||||
return stub(arg1, arg2)
|
||||
}
|
||||
if specificReturn {
|
||||
return ret.result1
|
||||
}
|
||||
return fakeReturns.result1
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) PersistParticipantCallCount() int {
|
||||
fake.persistParticipantMutex.RLock()
|
||||
defer fake.persistParticipantMutex.RUnlock()
|
||||
return len(fake.persistParticipantArgsForCall)
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) PersistParticipantCalls(stub func(string, *livekit.ParticipantInfo) error) {
|
||||
fake.persistParticipantMutex.Lock()
|
||||
defer fake.persistParticipantMutex.Unlock()
|
||||
fake.PersistParticipantStub = stub
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) PersistParticipantArgsForCall(i int) (string, *livekit.ParticipantInfo) {
|
||||
fake.persistParticipantMutex.RLock()
|
||||
defer fake.persistParticipantMutex.RUnlock()
|
||||
argsForCall := fake.persistParticipantArgsForCall[i]
|
||||
return argsForCall.arg1, argsForCall.arg2
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) PersistParticipantReturns(result1 error) {
|
||||
fake.persistParticipantMutex.Lock()
|
||||
defer fake.persistParticipantMutex.Unlock()
|
||||
fake.PersistParticipantStub = nil
|
||||
fake.persistParticipantReturns = struct {
|
||||
result1 error
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) PersistParticipantReturnsOnCall(i int, result1 error) {
|
||||
fake.persistParticipantMutex.Lock()
|
||||
defer fake.persistParticipantMutex.Unlock()
|
||||
fake.PersistParticipantStub = nil
|
||||
if fake.persistParticipantReturnsOnCall == nil {
|
||||
fake.persistParticipantReturnsOnCall = make(map[int]struct {
|
||||
result1 error
|
||||
})
|
||||
}
|
||||
fake.persistParticipantReturnsOnCall[i] = struct {
|
||||
result1 error
|
||||
}{result1}
|
||||
}
|
||||
|
||||
func (fake *FakeRoomStore) Invocations() map[string][][]interface{} {
|
||||
fake.invocationsMutex.RLock()
|
||||
defer fake.invocationsMutex.RUnlock()
|
||||
fake.createRoomMutex.RLock()
|
||||
defer fake.createRoomMutex.RUnlock()
|
||||
fake.deleteParticipantMutex.RLock()
|
||||
defer fake.deleteParticipantMutex.RUnlock()
|
||||
fake.deleteRoomMutex.RLock()
|
||||
defer fake.deleteRoomMutex.RUnlock()
|
||||
fake.getParticipantMutex.RLock()
|
||||
defer fake.getParticipantMutex.RUnlock()
|
||||
fake.getRoomMutex.RLock()
|
||||
defer fake.getRoomMutex.RUnlock()
|
||||
fake.listParticipantsMutex.RLock()
|
||||
defer fake.listParticipantsMutex.RUnlock()
|
||||
fake.listRoomsMutex.RLock()
|
||||
defer fake.listRoomsMutex.RUnlock()
|
||||
fake.persistParticipantMutex.RLock()
|
||||
defer fake.persistParticipantMutex.RUnlock()
|
||||
copiedInvocations := map[string][][]interface{}{}
|
||||
for key, value := range fake.invocations {
|
||||
copiedInvocations[key] = value
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package service_test
|
||||
|
||||
import (
|
||||
"github.com/go-redis/redis/v8"
|
||||
)
|
||||
|
||||
func redisClient() *redis.Client {
|
||||
return redis.NewClient(&redis.Options{
|
||||
Addr: "localhost:6379",
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user