add ctx to interfaces (#105)

* add ctx to interfaces

* use existing context
This commit is contained in:
David Colburn
2021-08-30 20:31:24 -05:00
committed by GitHub
parent 1e10d440c8
commit 1f1eea383f
17 changed files with 321 additions and 267 deletions
+11 -11
View File
@@ -38,7 +38,7 @@ func NewRedisRoomStore(rc *redis.Client) *RedisRoomStore {
}
}
func (p *RedisRoomStore) StoreRoom(room *livekit.Room) error {
func (p *RedisRoomStore) StoreRoom(ctx context.Context, room *livekit.Room) error {
if room.CreationTime == 0 {
room.CreationTime = time.Now().Unix()
}
@@ -58,7 +58,7 @@ func (p *RedisRoomStore) StoreRoom(room *livekit.Room) error {
return nil
}
func (p *RedisRoomStore) LoadRoom(idOrName string) (*livekit.Room, error) {
func (p *RedisRoomStore) LoadRoom(ctx context.Context, idOrName string) (*livekit.Room, error) {
// see if matches any ids
name, err := p.rc.HGet(p.ctx, RoomIdMap, idOrName).Result()
if err != nil {
@@ -82,7 +82,7 @@ func (p *RedisRoomStore) LoadRoom(idOrName string) (*livekit.Room, error) {
return &room, nil
}
func (p *RedisRoomStore) ListRooms() ([]*livekit.Room, error) {
func (p *RedisRoomStore) ListRooms(ctx context.Context) ([]*livekit.Room, error) {
items, err := p.rc.HVals(p.ctx, RoomsKey).Result()
if err != nil && err != redis.Nil {
return nil, errors.Wrap(err, "could not get rooms")
@@ -101,8 +101,8 @@ func (p *RedisRoomStore) ListRooms() ([]*livekit.Room, error) {
return rooms, nil
}
func (p *RedisRoomStore) DeleteRoom(idOrName string) error {
room, err := p.LoadRoom(idOrName)
func (p *RedisRoomStore) DeleteRoom(ctx context.Context, idOrName string) error {
room, err := p.LoadRoom(ctx, idOrName)
var sid, name string
if err == ErrRoomNotFound {
@@ -125,7 +125,7 @@ func (p *RedisRoomStore) DeleteRoom(idOrName string) error {
return err
}
func (p *RedisRoomStore) LockRoom(name string, duration time.Duration) (string, error) {
func (p *RedisRoomStore) LockRoom(ctx context.Context, name string, duration time.Duration) (string, error) {
token := utils.NewGuid("LOCK")
key := RoomLockPrefix + name
@@ -150,7 +150,7 @@ func (p *RedisRoomStore) LockRoom(name string, duration time.Duration) (string,
return "", ErrRoomLockFailed
}
func (p *RedisRoomStore) UnlockRoom(name string, uid string) error {
func (p *RedisRoomStore) UnlockRoom(ctx context.Context, name string, uid string) error {
key := RoomLockPrefix + name
val, err := p.rc.Get(p.ctx, key).Result()
@@ -167,7 +167,7 @@ func (p *RedisRoomStore) UnlockRoom(name string, uid string) error {
return p.rc.Del(p.ctx, key).Err()
}
func (p *RedisRoomStore) StoreParticipant(roomName string, participant *livekit.ParticipantInfo) error {
func (p *RedisRoomStore) StoreParticipant(ctx context.Context, roomName string, participant *livekit.ParticipantInfo) error {
key := RoomParticipantsPrefix + roomName
data, err := proto.Marshal(participant)
@@ -178,7 +178,7 @@ func (p *RedisRoomStore) StoreParticipant(roomName string, participant *livekit.
return p.rc.HSet(p.ctx, key, participant.Identity, data).Err()
}
func (p *RedisRoomStore) LoadParticipant(roomName, identity string) (*livekit.ParticipantInfo, error) {
func (p *RedisRoomStore) LoadParticipant(ctx context.Context, roomName, identity string) (*livekit.ParticipantInfo, error) {
key := RoomParticipantsPrefix + roomName
data, err := p.rc.HGet(p.ctx, key, identity).Result()
if err == redis.Nil {
@@ -194,7 +194,7 @@ func (p *RedisRoomStore) LoadParticipant(roomName, identity string) (*livekit.Pa
return &pi, nil
}
func (p *RedisRoomStore) ListParticipants(roomName string) ([]*livekit.ParticipantInfo, error) {
func (p *RedisRoomStore) ListParticipants(ctx context.Context, roomName string) ([]*livekit.ParticipantInfo, error) {
key := RoomParticipantsPrefix + roomName
items, err := p.rc.HVals(p.ctx, key).Result()
if err == redis.Nil {
@@ -214,7 +214,7 @@ func (p *RedisRoomStore) ListParticipants(roomName string) ([]*livekit.Participa
return participants, nil
}
func (p *RedisRoomStore) DeleteParticipant(roomName, identity string) error {
func (p *RedisRoomStore) DeleteParticipant(ctx context.Context, roomName, identity string) error {
key := RoomParticipantsPrefix + roomName
return p.rc.HDel(p.ctx, key, identity).Err()