Room Allocator Interface (#161)

* room allocator interface

* remove wire bind

* fix test
This commit is contained in:
Mathew Kamkar
2021-10-28 21:02:17 -07:00
committed by GitHub
parent 0898c17e8a
commit f3e916e2fe
7 changed files with 26 additions and 21 deletions
+4
View File
@@ -41,3 +41,7 @@ type RoomManager interface {
HasParticipants() bool HasParticipants() bool
Stop() Stop()
} }
type RoomAllocator interface {
CreateRoom(ctx context.Context, req *livekit.CreateRoomRequest) (*livekit.Room, error)
}
+15 -4
View File
@@ -13,20 +13,20 @@ import (
"github.com/livekit/livekit-server/pkg/routing/selector" "github.com/livekit/livekit-server/pkg/routing/selector"
) )
type RoomAllocator struct { type StandardRoomAllocator struct {
config *config.Config config *config.Config
router routing.Router router routing.Router
selector selector.NodeSelector selector selector.NodeSelector
roomStore RoomStore roomStore RoomStore
} }
func NewRoomAllocator(conf *config.Config, router routing.Router, rs RoomStore) (*RoomAllocator, error) { func NewRoomAllocator(conf *config.Config, router routing.Router, rs RoomStore) (RoomAllocator, error) {
ns, err := selector.CreateNodeSelector(conf) ns, err := selector.CreateNodeSelector(conf)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &RoomAllocator{ return &StandardRoomAllocator{
config: conf, config: conf,
router: router, router: router,
selector: ns, selector: ns,
@@ -36,7 +36,7 @@ func NewRoomAllocator(conf *config.Config, router routing.Router, rs RoomStore)
// CreateRoom creates a new room from a request and allocates it to a node to handle // CreateRoom creates a new room from a request and allocates it to a node to handle
// it'll also monitor its state, and cleans it up when appropriate // it'll also monitor its state, and cleans it up when appropriate
func (r *RoomAllocator) CreateRoom(ctx context.Context, req *livekit.CreateRoomRequest) (*livekit.Room, error) { func (r *StandardRoomAllocator) CreateRoom(ctx context.Context, req *livekit.CreateRoomRequest) (*livekit.Room, error) {
token, err := r.roomStore.LockRoom(ctx, req.Name, 5*time.Second) token, err := r.roomStore.LockRoom(ctx, req.Name, 5*time.Second)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -104,3 +104,14 @@ func (r *RoomAllocator) CreateRoom(ctx context.Context, req *livekit.CreateRoomR
return rm, nil return rm, nil
} }
func applyDefaultRoomConfig(room *livekit.Room, conf *config.RoomConfig) {
room.EmptyTimeout = conf.EmptyTimeout
room.MaxParticipants = conf.MaxParticipants
for _, codec := range conf.EnabledCodecs {
room.EnabledCodecs = append(room.EnabledCodecs, &livekit.Codec{
Mime: codec.Mime,
FmtpLine: codec.FmtpLine,
})
}
}
+1 -1
View File
@@ -25,7 +25,7 @@ func TestCreateRoom(t *testing.T) {
}) })
} }
func newTestRoomAllocator(t *testing.T) (*service.RoomAllocator, *config.Config) { func newTestRoomAllocator(t *testing.T) (service.RoomAllocator, *config.Config) {
store := &servicefakes.FakeRoomStore{} store := &servicefakes.FakeRoomStore{}
store.LoadRoomReturns(nil, service.ErrRoomNotFound) store.LoadRoomReturns(nil, service.ErrRoomNotFound)
router := &routingfakes.FakeRouter{} router := &routingfakes.FakeRouter{}
-11
View File
@@ -571,17 +571,6 @@ func (r *LocalRoomManager) notifyEvent(event *livekit.WebhookEvent) {
}) })
} }
func applyDefaultRoomConfig(room *livekit.Room, conf *config.RoomConfig) {
room.EmptyTimeout = conf.EmptyTimeout
room.MaxParticipants = conf.MaxParticipants
for _, codec := range conf.EnabledCodecs {
room.EnabledCodecs = append(room.EnabledCodecs, &livekit.Codec{
Mime: codec.Mime,
FmtpLine: codec.FmtpLine,
})
}
}
func iceServerForStunServers(servers []string) *livekit.ICEServer { func iceServerForStunServers(servers []string) *livekit.ICEServer {
iceServer := &livekit.ICEServer{} iceServer := &livekit.ICEServer{}
for _, stunServer := range servers { for _, stunServer := range servers {
+2 -2
View File
@@ -14,11 +14,11 @@ import (
// A rooms service that supports a single node // A rooms service that supports a single node
type RoomService struct { type RoomService struct {
router routing.Router router routing.Router
roomAllocator *RoomAllocator roomAllocator RoomAllocator
roomStore RoomStore roomStore RoomStore
} }
func NewRoomService(ra *RoomAllocator, rs RoomStore, router routing.Router) (svc *RoomService, err error) { func NewRoomService(ra RoomAllocator, rs RoomStore, router routing.Router) (svc *RoomService, err error) {
svc = &RoomService{ svc = &RoomService{
router: router, router: router,
roomAllocator: ra, roomAllocator: ra,
+2 -2
View File
@@ -21,13 +21,13 @@ import (
type RTCService struct { type RTCService struct {
router routing.Router router routing.Router
roomAllocator *RoomAllocator roomAllocator RoomAllocator
upgrader websocket.Upgrader upgrader websocket.Upgrader
currentNode routing.LocalNode currentNode routing.LocalNode
isDev bool isDev bool
} }
func NewRTCService(conf *config.Config, ra *RoomAllocator, router routing.Router, currentNode routing.LocalNode) *RTCService { func NewRTCService(conf *config.Config, ra RoomAllocator, router routing.Router, currentNode routing.LocalNode) *RTCService {
s := &RTCService{ s := &RTCService{
router: router, router: router,
roomAllocator: ra, roomAllocator: ra,
+2 -1
View File
@@ -1,4 +1,5 @@
//+build wireinject //go:build wireinject
// +build wireinject
package service package service