mirror of
https://github.com/livekit/livekit.git
synced 2026-08-02 15:39:43 +00:00
Room Allocator Interface (#161)
* room allocator interface * remove wire bind * fix test
This commit is contained in:
@@ -41,3 +41,7 @@ type RoomManager interface {
|
||||
HasParticipants() bool
|
||||
Stop()
|
||||
}
|
||||
|
||||
type RoomAllocator interface {
|
||||
CreateRoom(ctx context.Context, req *livekit.CreateRoomRequest) (*livekit.Room, error)
|
||||
}
|
||||
|
||||
@@ -13,20 +13,20 @@ import (
|
||||
"github.com/livekit/livekit-server/pkg/routing/selector"
|
||||
)
|
||||
|
||||
type RoomAllocator struct {
|
||||
type StandardRoomAllocator struct {
|
||||
config *config.Config
|
||||
router routing.Router
|
||||
selector selector.NodeSelector
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &RoomAllocator{
|
||||
return &StandardRoomAllocator{
|
||||
config: conf,
|
||||
router: router,
|
||||
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
|
||||
// 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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -104,3 +104,14 @@ func (r *RoomAllocator) CreateRoom(ctx context.Context, req *livekit.CreateRoomR
|
||||
|
||||
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,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.LoadRoomReturns(nil, service.ErrRoomNotFound)
|
||||
router := &routingfakes.FakeRouter{}
|
||||
|
||||
@@ -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 {
|
||||
iceServer := &livekit.ICEServer{}
|
||||
for _, stunServer := range servers {
|
||||
|
||||
@@ -14,11 +14,11 @@ import (
|
||||
// A rooms service that supports a single node
|
||||
type RoomService struct {
|
||||
router routing.Router
|
||||
roomAllocator *RoomAllocator
|
||||
roomAllocator RoomAllocator
|
||||
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{
|
||||
router: router,
|
||||
roomAllocator: ra,
|
||||
|
||||
@@ -21,13 +21,13 @@ import (
|
||||
|
||||
type RTCService struct {
|
||||
router routing.Router
|
||||
roomAllocator *RoomAllocator
|
||||
roomAllocator RoomAllocator
|
||||
upgrader websocket.Upgrader
|
||||
currentNode routing.LocalNode
|
||||
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{
|
||||
router: router,
|
||||
roomAllocator: ra,
|
||||
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
//+build wireinject
|
||||
//go:build wireinject
|
||||
// +build wireinject
|
||||
|
||||
package service
|
||||
|
||||
|
||||
Reference in New Issue
Block a user