config rework to handle distributed setup, fixed redis bugs

This commit is contained in:
David Zhao
2021-01-17 17:06:50 -08:00
parent 30e99e8c6b
commit 458241d1f1
21 changed files with 382 additions and 104 deletions
+21 -1
View File
@@ -4,8 +4,10 @@ import (
"context"
"time"
"github.com/thoas/go-funk"
"github.com/twitchtv/twirp"
"github.com/livekit/livekit-server/pkg/routing"
"github.com/livekit/livekit-server/pkg/utils"
"github.com/livekit/livekit-server/proto/livekit"
)
@@ -13,11 +15,13 @@ import (
// A rooms service that supports a single node
type RoomService struct {
roomProvider RoomStore
router routing.Router
}
func NewRoomService(rp RoomStore) (svc *RoomService, err error) {
func NewRoomService(rp RoomStore, router routing.Router) (svc *RoomService, err error) {
svc = &RoomService{
roomProvider: rp,
router: router,
}
return
@@ -40,6 +44,22 @@ func (s *RoomService) CreateRoom(ctx context.Context, req *livekit.CreateRoomReq
return
}
// allocate room to a node
nodes, err := s.router.ListNodes()
if err != nil {
return
}
if len(nodes) == 0 {
return nil, ErrNoRegisteredNodes
}
idx := funk.RandomInt(0, len(nodes))
node := nodes[idx]
if err = s.router.SetNodeForRoom(req.Name, node.Id); err != nil {
return
}
return
}