add ctx to interfaces (#105)
* add ctx to interfaces * use existing context
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
@@ -28,7 +29,7 @@ func NewLocalRoomStore() *LocalRoomStore {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) StoreRoom(room *livekit.Room) error {
|
||||
func (p *LocalRoomStore) StoreRoom(ctx context.Context, room *livekit.Room) error {
|
||||
if room.CreationTime == 0 {
|
||||
room.CreationTime = time.Now().Unix()
|
||||
}
|
||||
@@ -39,7 +40,7 @@ func (p *LocalRoomStore) StoreRoom(room *livekit.Room) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) LoadRoom(idOrName string) (*livekit.Room, error) {
|
||||
func (p *LocalRoomStore) LoadRoom(ctx context.Context, idOrName string) (*livekit.Room, error) {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
// see if it's an id or name
|
||||
@@ -54,7 +55,7 @@ func (p *LocalRoomStore) LoadRoom(idOrName string) (*livekit.Room, error) {
|
||||
return room, nil
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) ListRooms() ([]*livekit.Room, error) {
|
||||
func (p *LocalRoomStore) ListRooms(ctx context.Context) ([]*livekit.Room, error) {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
rooms := make([]*livekit.Room, 0, len(p.rooms))
|
||||
@@ -64,8 +65,8 @@ func (p *LocalRoomStore) ListRooms() ([]*livekit.Room, error) {
|
||||
return rooms, nil
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) DeleteRoom(idOrName string) error {
|
||||
room, err := p.LoadRoom(idOrName)
|
||||
func (p *LocalRoomStore) DeleteRoom(ctx context.Context, idOrName string) error {
|
||||
room, err := p.LoadRoom(ctx, idOrName)
|
||||
if err == ErrRoomNotFound {
|
||||
return nil
|
||||
} else if err != nil {
|
||||
@@ -81,18 +82,18 @@ func (p *LocalRoomStore) DeleteRoom(idOrName string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) LockRoom(name string, duration time.Duration) (string, error) {
|
||||
func (p *LocalRoomStore) LockRoom(ctx context.Context, name string, duration time.Duration) (string, error) {
|
||||
// local rooms lock & unlock globally
|
||||
p.globalLock.Lock()
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) UnlockRoom(name string, uid string) error {
|
||||
func (p *LocalRoomStore) UnlockRoom(ctx context.Context, name string, uid string) error {
|
||||
p.globalLock.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) StoreParticipant(roomName string, participant *livekit.ParticipantInfo) error {
|
||||
func (p *LocalRoomStore) StoreParticipant(ctx context.Context, roomName string, participant *livekit.ParticipantInfo) error {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
roomParticipants := p.participants[roomName]
|
||||
@@ -104,7 +105,7 @@ func (p *LocalRoomStore) StoreParticipant(roomName string, participant *livekit.
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) LoadParticipant(roomName, identity string) (*livekit.ParticipantInfo, error) {
|
||||
func (p *LocalRoomStore) LoadParticipant(ctx context.Context, roomName, identity string) (*livekit.ParticipantInfo, error) {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
|
||||
@@ -119,7 +120,7 @@ func (p *LocalRoomStore) LoadParticipant(roomName, identity string) (*livekit.Pa
|
||||
return participant, nil
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) ListParticipants(roomName string) ([]*livekit.ParticipantInfo, error) {
|
||||
func (p *LocalRoomStore) ListParticipants(ctx context.Context, roomName string) ([]*livekit.ParticipantInfo, error) {
|
||||
p.lock.RLock()
|
||||
defer p.lock.RUnlock()
|
||||
|
||||
@@ -137,7 +138,7 @@ func (p *LocalRoomStore) ListParticipants(roomName string) ([]*livekit.Participa
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func (p *LocalRoomStore) DeleteParticipant(roomName, identity string) error {
|
||||
func (p *LocalRoomStore) DeleteParticipant(ctx context.Context, roomName, identity string) error {
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user