Ability to disable auto-create (#361)

* setting to disable autocreate

* improve test reliability

* update comment

* update to address feedback
This commit is contained in:
David Zhao
2022-01-21 09:57:36 -08:00
committed by GitHub
parent 7f4ead9b25
commit 126bb8867b
13 changed files with 178 additions and 22 deletions
+22 -1
View File
@@ -1,6 +1,7 @@
package service
import (
"context"
"fmt"
"io"
"net/http"
@@ -23,18 +24,28 @@ import (
type RTCService struct {
router routing.MessageRouter
roomAllocator RoomAllocator
store RoomStore
upgrader websocket.Upgrader
currentNode routing.LocalNode
config *config.Config
isDev bool
limits config.LimitConfig
}
func NewRTCService(conf *config.Config, ra RoomAllocator, router routing.MessageRouter, currentNode routing.LocalNode) *RTCService {
func NewRTCService(
conf *config.Config,
ra RoomAllocator,
store RoomStore,
router routing.MessageRouter,
currentNode routing.LocalNode,
) *RTCService {
s := &RTCService{
router: router,
roomAllocator: ra,
store: store,
upgrader: websocket.Upgrader{},
currentNode: currentNode,
config: conf,
isDev: conf.Development,
limits: conf.Limit,
}
@@ -130,6 +141,16 @@ func (s *RTCService) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
// when autocreate is disabled, we'll check to ensure it's already created
if !s.config.Room.AutoCreate {
_, err := s.store.LoadRoom(context.Background(), roomName)
if err == ErrRoomNotFound {
handleError(w, 404, err.Error())
} else if err != nil {
handleError(w, 500, err.Error())
}
}
// create room if it doesn't exist, also assigns an RTC node for the room
rm, err := s.roomAllocator.CreateRoom(r.Context(), &livekit.CreateRoomRequest{Name: string(roomName)})
if err != nil {