Some more files with types (#302)
This commit is contained in:
+3
-2
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/twitchtv/twirp"
|
||||
|
||||
"github.com/livekit/protocol/auth"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -92,7 +93,7 @@ func SetAuthorizationToken(r *http.Request, token string) {
|
||||
r.Header.Set(authorizationHeader, bearerPrefix+token)
|
||||
}
|
||||
|
||||
func EnsureJoinPermission(ctx context.Context) (name string, err error) {
|
||||
func EnsureJoinPermission(ctx context.Context) (name livekit.RoomName, err error) {
|
||||
claims := GetGrants(ctx)
|
||||
if claims == nil || claims.Video == nil {
|
||||
err = ErrPermissionDenied
|
||||
@@ -107,7 +108,7 @@ func EnsureJoinPermission(ctx context.Context) (name string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func EnsureAdminPermission(ctx context.Context, room string) error {
|
||||
func EnsureAdminPermission(ctx context.Context, room livekit.RoomName) error {
|
||||
claims := GetGrants(ctx)
|
||||
if claims == nil || claims.Video == nil {
|
||||
return ErrPermissionDenied
|
||||
|
||||
@@ -16,25 +16,25 @@ type RoomStore interface {
|
||||
|
||||
// enable locking on a specific room to prevent race
|
||||
// returns a (lock uuid, error)
|
||||
LockRoom(ctx context.Context, name string, duration time.Duration) (string, error)
|
||||
UnlockRoom(ctx context.Context, name string, uid string) error
|
||||
LockRoom(ctx context.Context, name livekit.RoomName, duration time.Duration) (string, error)
|
||||
UnlockRoom(ctx context.Context, name livekit.RoomName, uid string) error
|
||||
|
||||
StoreRoom(ctx context.Context, room *livekit.Room) error
|
||||
DeleteRoom(ctx context.Context, name string) error
|
||||
DeleteRoom(ctx context.Context, name livekit.RoomName) error
|
||||
|
||||
StoreParticipant(ctx context.Context, roomName string, participant *livekit.ParticipantInfo) error
|
||||
DeleteParticipant(ctx context.Context, roomName, identity string) error
|
||||
StoreParticipant(ctx context.Context, roomName livekit.RoomName, participant *livekit.ParticipantInfo) error
|
||||
DeleteParticipant(ctx context.Context, roomName livekit.RoomName, identity livekit.ParticipantIdentity) error
|
||||
}
|
||||
|
||||
//counterfeiter:generate . RORoomStore
|
||||
type RORoomStore interface {
|
||||
LoadRoom(ctx context.Context, name string) (*livekit.Room, error)
|
||||
LoadRoom(ctx context.Context, name livekit.RoomName) (*livekit.Room, error)
|
||||
// ListRooms returns currently active rooms. if names is not nil, it'll filter and return
|
||||
// only rooms that match
|
||||
ListRooms(ctx context.Context, names []string) ([]*livekit.Room, error)
|
||||
ListRooms(ctx context.Context, names []livekit.RoomName) ([]*livekit.Room, error)
|
||||
|
||||
LoadParticipant(ctx context.Context, roomName, identity string) (*livekit.ParticipantInfo, error)
|
||||
ListParticipants(ctx context.Context, roomName string) ([]*livekit.ParticipantInfo, error)
|
||||
LoadParticipant(ctx context.Context, roomName livekit.RoomName, identity livekit.ParticipantIdentity) (*livekit.ParticipantInfo, error)
|
||||
ListParticipants(ctx context.Context, roomName livekit.RoomName) ([]*livekit.ParticipantInfo, error)
|
||||
}
|
||||
|
||||
//counterfeiter:generate . RoomAllocator
|
||||
|
||||
@@ -12,17 +12,17 @@ import (
|
||||
// encapsulates CRUD operations for room settings
|
||||
type LocalRoomStore struct {
|
||||
// map of roomName => room
|
||||
rooms map[string]*livekit.Room
|
||||
rooms map[livekit.RoomName]*livekit.Room
|
||||
// map of roomName => { identity: participant }
|
||||
participants map[string]map[string]*livekit.ParticipantInfo
|
||||
participants map[livekit.RoomName]map[livekit.ParticipantIdentity]*livekit.ParticipantInfo
|
||||
lock sync.RWMutex
|
||||
globalLock sync.Mutex
|
||||
}
|
||||
|
||||
func NewLocalRoomStore() *LocalRoomStore {
|
||||
return &LocalRoomStore{
|
||||
rooms: make(map[string]*livekit.Room),
|
||||
participants: make(map[string]map[string]*livekit.ParticipantInfo),
|
||||
rooms: make(map[livekit.RoomName]*livekit.Room),
|
||||
participants: make(map[livekit.RoomName]map[livekit.ParticipantIdentity]*livekit.ParticipantInfo),
|
||||
lock: sync.RWMutex{},
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ func (p *LocalRoomStore) StoreRoom(_ context.Context, room *livekit.Room) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) LoadRoom(_ context.Context, name string) (*livekit.Room, error) {
|
||||
func (p *LocalRoomStore) LoadRoom(_ context.Context, name livekit.RoomName) (*livekit.Room, error) {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
|
||||
@@ -48,7 +48,7 @@ func (p *LocalRoomStore) LoadRoom(_ context.Context, name string) (*livekit.Room
|
||||
return room, nil
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) ListRooms(_ context.Context, names []string) ([]*livekit.Room, error) {
|
||||
func (p *LocalRoomStore) ListRooms(_ context.Context, names []livekit.RoomName) ([]*livekit.Room, error) {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
rooms := make([]*livekit.Room, 0, len(p.rooms))
|
||||
@@ -60,7 +60,7 @@ func (p *LocalRoomStore) ListRooms(_ context.Context, names []string) ([]*liveki
|
||||
return rooms, nil
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) DeleteRoom(ctx context.Context, name string) error {
|
||||
func (p *LocalRoomStore) DeleteRoom(ctx context.Context, name livekit.RoomName) error {
|
||||
room, err := p.LoadRoom(ctx, name)
|
||||
if err == ErrRoomNotFound {
|
||||
return nil
|
||||
@@ -76,30 +76,30 @@ func (p *LocalRoomStore) DeleteRoom(ctx context.Context, name string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) LockRoom(_ context.Context, _ string, _ time.Duration) (string, error) {
|
||||
func (p *LocalRoomStore) LockRoom(_ context.Context, _ livekit.RoomName, _ time.Duration) (string, error) {
|
||||
// local rooms lock & unlock globally
|
||||
p.globalLock.Lock()
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) UnlockRoom(_ context.Context, _ string, _ string) error {
|
||||
func (p *LocalRoomStore) UnlockRoom(_ context.Context, _ livekit.RoomName, _ string) error {
|
||||
p.globalLock.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) StoreParticipant(_ context.Context, roomName string, participant *livekit.ParticipantInfo) error {
|
||||
func (p *LocalRoomStore) StoreParticipant(_ context.Context, roomName livekit.RoomName, participant *livekit.ParticipantInfo) error {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
roomParticipants := p.participants[roomName]
|
||||
if roomParticipants == nil {
|
||||
roomParticipants = make(map[string]*livekit.ParticipantInfo)
|
||||
roomParticipants = make(map[livekit.ParticipantIdentity]*livekit.ParticipantInfo)
|
||||
p.participants[roomName] = roomParticipants
|
||||
}
|
||||
roomParticipants[participant.Identity] = participant
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) LoadParticipant(_ context.Context, roomName, identity string) (*livekit.ParticipantInfo, error) {
|
||||
func (p *LocalRoomStore) LoadParticipant(_ context.Context, roomName, identity livekit.ParticipantIdentity) (*livekit.ParticipantInfo, error) {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
|
||||
@@ -114,7 +114,7 @@ func (p *LocalRoomStore) LoadParticipant(_ context.Context, roomName, identity s
|
||||
return participant, nil
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) ListParticipants(_ context.Context, roomName string) ([]*livekit.ParticipantInfo, error) {
|
||||
func (p *LocalRoomStore) ListParticipants(_ context.Context, roomName livekit.RoomName) ([]*livekit.ParticipantInfo, error) {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
|
||||
@@ -132,7 +132,7 @@ func (p *LocalRoomStore) ListParticipants(_ context.Context, roomName string) ([
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) DeleteParticipant(_ context.Context, roomName, identity string) error {
|
||||
func (p *LocalRoomStore) DeleteParticipant(_ context.Context, roomName, identity livekit.ParticipantIdentity) error {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ func (p *RedisRoomStore) StoreRoom(_ context.Context, room *livekit.Room) error
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *RedisRoomStore) LoadRoom(_ context.Context, name string) (*livekit.Room, error) {
|
||||
func (p *RedisRoomStore) LoadRoom(_ context.Context, name livekit.RoomName) (*livekit.Room, error) {
|
||||
data, err := p.rc.HGet(p.ctx, RoomsKey, name).Result()
|
||||
if err != nil {
|
||||
if err == redis.Nil {
|
||||
@@ -72,7 +72,7 @@ func (p *RedisRoomStore) LoadRoom(_ context.Context, name string) (*livekit.Room
|
||||
return &room, nil
|
||||
}
|
||||
|
||||
func (p *RedisRoomStore) ListRooms(_ context.Context, names []string) ([]*livekit.Room, error) {
|
||||
func (p *RedisRoomStore) ListRooms(_ context.Context, names []livekit.RoomName) ([]*livekit.Room, error) {
|
||||
var items []string
|
||||
var err error
|
||||
if names == nil {
|
||||
@@ -106,7 +106,7 @@ func (p *RedisRoomStore) ListRooms(_ context.Context, names []string) ([]*liveki
|
||||
return rooms, nil
|
||||
}
|
||||
|
||||
func (p *RedisRoomStore) DeleteRoom(ctx context.Context, name string) error {
|
||||
func (p *RedisRoomStore) DeleteRoom(ctx context.Context, name livekit.RoomName) error {
|
||||
_, err := p.LoadRoom(ctx, name)
|
||||
if err == ErrRoomNotFound {
|
||||
return nil
|
||||
@@ -120,7 +120,7 @@ func (p *RedisRoomStore) DeleteRoom(ctx context.Context, name string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *RedisRoomStore) LockRoom(_ context.Context, name string, duration time.Duration) (string, error) {
|
||||
func (p *RedisRoomStore) LockRoom(_ context.Context, name livekit.RoomName, duration time.Duration) (string, error) {
|
||||
token := utils.NewGuid("LOCK")
|
||||
key := RoomLockPrefix + name
|
||||
|
||||
@@ -145,7 +145,7 @@ func (p *RedisRoomStore) LockRoom(_ context.Context, name string, duration time.
|
||||
return "", ErrRoomLockFailed
|
||||
}
|
||||
|
||||
func (p *RedisRoomStore) UnlockRoom(_ context.Context, name string, uid string) error {
|
||||
func (p *RedisRoomStore) UnlockRoom(_ context.Context, name livekit.RoomName, uid string) error {
|
||||
key := RoomLockPrefix + name
|
||||
|
||||
val, err := p.rc.Get(p.ctx, key).Result()
|
||||
@@ -162,7 +162,7 @@ func (p *RedisRoomStore) UnlockRoom(_ context.Context, name string, uid string)
|
||||
return p.rc.Del(p.ctx, key).Err()
|
||||
}
|
||||
|
||||
func (p *RedisRoomStore) StoreParticipant(_ context.Context, roomName string, participant *livekit.ParticipantInfo) error {
|
||||
func (p *RedisRoomStore) StoreParticipant(_ context.Context, roomName livekit.RoomName, participant *livekit.ParticipantInfo) error {
|
||||
key := RoomParticipantsPrefix + roomName
|
||||
|
||||
data, err := proto.Marshal(participant)
|
||||
@@ -173,7 +173,7 @@ func (p *RedisRoomStore) StoreParticipant(_ context.Context, roomName string, pa
|
||||
return p.rc.HSet(p.ctx, key, participant.Identity, data).Err()
|
||||
}
|
||||
|
||||
func (p *RedisRoomStore) LoadParticipant(_ context.Context, roomName, identity string) (*livekit.ParticipantInfo, error) {
|
||||
func (p *RedisRoomStore) LoadParticipant(_ context.Context, roomName livekit.RoomName, identity livekit.ParticipantIdentity) (*livekit.ParticipantInfo, error) {
|
||||
key := RoomParticipantsPrefix + roomName
|
||||
data, err := p.rc.HGet(p.ctx, key, identity).Result()
|
||||
if err == redis.Nil {
|
||||
@@ -189,7 +189,7 @@ func (p *RedisRoomStore) LoadParticipant(_ context.Context, roomName, identity s
|
||||
return &pi, nil
|
||||
}
|
||||
|
||||
func (p *RedisRoomStore) ListParticipants(_ context.Context, roomName string) ([]*livekit.ParticipantInfo, error) {
|
||||
func (p *RedisRoomStore) ListParticipants(_ context.Context, roomName livekit.RoomName) ([]*livekit.ParticipantInfo, error) {
|
||||
key := RoomParticipantsPrefix + roomName
|
||||
items, err := p.rc.HVals(p.ctx, key).Result()
|
||||
if err == redis.Nil {
|
||||
@@ -209,7 +209,7 @@ func (p *RedisRoomStore) ListParticipants(_ context.Context, roomName string) ([
|
||||
return participants, nil
|
||||
}
|
||||
|
||||
func (p *RedisRoomStore) DeleteParticipant(_ context.Context, roomName, identity string) error {
|
||||
func (p *RedisRoomStore) DeleteParticipant(_ context.Context, roomName livekit.RoomName, identity livekit.ParticipantIdentity) error {
|
||||
key := RoomParticipantsPrefix + roomName
|
||||
|
||||
return p.rc.HDel(p.ctx, key, identity).Err()
|
||||
|
||||
@@ -46,7 +46,7 @@ func (s *RoomService) ListRooms(ctx context.Context, req *livekit.ListRoomsReque
|
||||
return nil, twirpAuthError(err)
|
||||
}
|
||||
|
||||
var names []string
|
||||
var names []livekit.RoomName
|
||||
if len(req.Names) > 0 {
|
||||
names = req.Names
|
||||
}
|
||||
@@ -225,7 +225,7 @@ func (s *RoomService) UpdateRoomMetadata(ctx context.Context, req *livekit.Updat
|
||||
return room, nil
|
||||
}
|
||||
|
||||
func (s *RoomService) writeParticipantMessage(ctx context.Context, room, identity string, msg *livekit.RTCNodeMessage) error {
|
||||
func (s *RoomService) writeParticipantMessage(ctx context.Context, room livekit.RoomName, identity livekit.ParticipantIdentity, msg *livekit.RTCNodeMessage) error {
|
||||
if err := EnsureAdminPermission(ctx, room); err != nil {
|
||||
return twirpAuthError(err)
|
||||
}
|
||||
@@ -238,7 +238,7 @@ func (s *RoomService) writeParticipantMessage(ctx context.Context, room, identit
|
||||
return s.router.WriteParticipantRTC(ctx, room, identity, msg)
|
||||
}
|
||||
|
||||
func (s *RoomService) writeRoomMessage(ctx context.Context, room, identity string, msg *livekit.RTCNodeMessage) error {
|
||||
func (s *RoomService) writeRoomMessage(ctx context.Context, room livekit.RoomName, identity livekit.ParticipantIdentity, msg *livekit.RTCNodeMessage) error {
|
||||
if err := EnsureAdminPermission(ctx, room); err != nil {
|
||||
return twirpAuthError(err)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// Code generated by Wire. DO NOT EDIT.
|
||||
|
||||
//go:generate go run github.com/google/wire/cmd/wire
|
||||
//+build !wireinject
|
||||
//go:build !wireinject
|
||||
// +build !wireinject
|
||||
|
||||
package service
|
||||
|
||||
|
||||
Reference in New Issue
Block a user