Ability to disable auto-create (#361)
* setting to disable autocreate * improve test reliability * update comment * update to address feedback
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user