From e5d21cb1d9d2f3c7b9585c36802443221192e970 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Wed, 9 Nov 2022 23:35:35 -0800 Subject: [PATCH] CreateRoom API to actually create the room on an RTC node (#1155) Previously, CreateRoom only created the room in storage, but did not hydrate it on an RTC node. This has caused strange behaviors such as emptyTimeout not working correctly (#1109). Also reduced room reap worker to consistently reap rooms. Fixes #241 --- pkg/service/roommanager.go | 4 ++++ pkg/service/roomservice.go | 11 +++++++++++ pkg/service/server.go | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/service/roommanager.go b/pkg/service/roommanager.go index 4b9060c53..5ba4a1824 100644 --- a/pkg/service/roommanager.go +++ b/pkg/service/roommanager.go @@ -219,6 +219,10 @@ func (r *RoomManager) StartSession( } defer room.Release() + // only create the room, but don't start a participant session + if pi.Identity == "" { + return nil + } participant := room.GetParticipant(pi.Identity) if participant != nil { // When reconnecting, it means WS has interrupted by underlying peer connection is still ok diff --git a/pkg/service/roomservice.go b/pkg/service/roomservice.go index 020144c16..ce7539c66 100644 --- a/pkg/service/roomservice.go +++ b/pkg/service/roomservice.go @@ -61,6 +61,17 @@ func (s *RoomService) CreateRoom(ctx context.Context, req *livekit.CreateRoomReq return nil, err } + // actually start the room on an RTC node, to ensure metadata & empty timeout functionality + _, sink, source, err := s.router.StartParticipantSignal(ctx, + livekit.RoomName(req.Name), + routing.ParticipantInit{}, + ) + if err != nil { + return nil, err + } + sink.Close() + source.Close() + if req.Egress != nil && req.Egress.Room != nil { egress := &livekit.StartEgressRequest{ Request: &livekit.StartEgressRequest_RoomComposite{ diff --git a/pkg/service/server.go b/pkg/service/server.go index 60a94b9e9..b15355c0a 100644 --- a/pkg/service/server.go +++ b/pkg/service/server.go @@ -328,7 +328,7 @@ func (s *LivekitServer) healthCheck(w http.ResponseWriter, _ *http.Request) { // worker to perform periodic tasks per node func (s *LivekitServer) backgroundWorker() { - roomTicker := time.NewTicker(30 * time.Second) + roomTicker := time.NewTicker(1 * time.Second) defer roomTicker.Stop() for { select {