auto-create rooms upon creation
This commit is contained in:
+8
-3
@@ -43,9 +43,14 @@ func main() {
|
||||
Usage: "path to file that contains API keys/secrets",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "keys",
|
||||
Usage: "API keys/secret pairs (key:secret, one per line)",
|
||||
EnvVars: []string{"LIVEKIT_KEYS"},
|
||||
Name: "redis-host",
|
||||
Usage: "host (incl. port) to redis server",
|
||||
EnvVars: []string{"REDIS_HOST"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "redis-password",
|
||||
Usage: "password to redis",
|
||||
EnvVars: []string{"REDIS_PASSWORD"},
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "cpuprofile",
|
||||
|
||||
@@ -64,13 +64,12 @@ func (conf *Config) UpdateFromCLI(c *cli.Context) error {
|
||||
if c.IsSet("key-file") {
|
||||
conf.KeyFile = c.String("key-file")
|
||||
}
|
||||
if c.IsSet("keys") {
|
||||
conf.Keys = make(map[string]string)
|
||||
if err := yaml.Unmarshal([]byte(c.String("keys")), conf.Keys); err != nil {
|
||||
return err
|
||||
}
|
||||
if c.IsSet("redis-host") {
|
||||
conf.Redis.Address = c.String("redis-host")
|
||||
}
|
||||
if c.IsSet("redis-password") {
|
||||
conf.Redis.Password = c.String("redis-password")
|
||||
}
|
||||
|
||||
// expand env vars in filenames
|
||||
file, err := homedir.Expand(os.ExpandEnv(conf.KeyFile))
|
||||
if err != nil {
|
||||
|
||||
@@ -18,16 +18,16 @@ import (
|
||||
|
||||
type RTCService struct {
|
||||
router routing.Router
|
||||
roomStore RoomStore
|
||||
roomManager *RoomManager
|
||||
upgrader websocket.Upgrader
|
||||
currentNode routing.LocalNode
|
||||
isDev bool
|
||||
}
|
||||
|
||||
func NewRTCService(conf *config.Config, roomStore RoomStore, router routing.Router, currentNode routing.LocalNode) *RTCService {
|
||||
func NewRTCService(conf *config.Config, roomStore RoomStore, roomManager *RoomManager, router routing.Router, currentNode routing.LocalNode) *RTCService {
|
||||
s := &RTCService{
|
||||
router: router,
|
||||
roomStore: roomStore,
|
||||
roomManager: roomManager,
|
||||
upgrader: websocket.Upgrader{},
|
||||
currentNode: currentNode,
|
||||
isDev: conf.Development,
|
||||
@@ -60,13 +60,15 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
roomName = onlyName
|
||||
}
|
||||
|
||||
rm, err := s.roomStore.GetRoom(roomName)
|
||||
if err != nil {
|
||||
handleError(w, http.StatusNotFound, err.Error())
|
||||
return
|
||||
rm, err := s.roomManager.roomStore.GetRoom(roomName)
|
||||
if err == ErrRoomNotFound {
|
||||
rm, err = s.roomManager.CreateRoom(&livekit.CreateRoomRequest{Name: roomName})
|
||||
}
|
||||
|
||||
// TODO: assign room to a node if for some reasons node isn't available
|
||||
if err != nil {
|
||||
handleError(w, http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// upgrade only once the basics are good to go
|
||||
conn, err := s.upgrader.Upgrade(w, r, nil)
|
||||
|
||||
@@ -26,7 +26,7 @@ func InitializeServer(conf *config.Config, keyProvider auth.KeyProvider, roomSto
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
rtcService := NewRTCService(conf, roomStore, router, currentNode)
|
||||
rtcService := NewRTCService(conf, roomStore, roomManager, router, currentNode)
|
||||
livekitServer, err := NewLivekitServer(conf, roomService, rtcService, keyProvider, router, roomManager, currentNode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
func TestMultiNodeRouting(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
return
|
||||
}
|
||||
|
||||
s1, s2 := setupMultiNodeTest()
|
||||
@@ -68,3 +69,18 @@ func TestMultiNodeRouting(t *testing.T) {
|
||||
assert.Equal(t, redis.Nil, rc.HGet(ctx, routing.NodeRoomKey, testRoom).Err())
|
||||
assert.Equal(t, redis.Nil, rc.HGet(ctx, service.RoomIdMap, testRoom).Err())
|
||||
}
|
||||
|
||||
func TestConnectWithoutCreation(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
return
|
||||
}
|
||||
s1, s2 := setupMultiNodeTest()
|
||||
defer s1.Stop()
|
||||
defer s2.Stop()
|
||||
|
||||
c1 := createRTCClient("c1", defaultServerPort)
|
||||
waitUntilConnected(t, c1)
|
||||
|
||||
c1.Stop()
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
func TestClientCouldConnect(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
return
|
||||
}
|
||||
|
||||
s := setupSingleNodeTest(testRoom)
|
||||
@@ -33,6 +34,7 @@ func TestClientCouldConnect(t *testing.T) {
|
||||
func TestSinglePublisher(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.SkipNow()
|
||||
return
|
||||
}
|
||||
|
||||
s := setupSingleNodeTest(testRoom)
|
||||
|
||||
Reference in New Issue
Block a user