* agents

* add test

* undo name changes

* remove debug logs

* fixes

* fix data race in test
This commit is contained in:
David Colburn
2023-11-03 11:43:35 -07:00
committed by GitHub
parent f5047ab653
commit 60374c6402
20 changed files with 931 additions and 91 deletions
+29 -8
View File
@@ -31,6 +31,7 @@ import (
"github.com/livekit/protocol/livekit"
"github.com/livekit/protocol/logger"
"github.com/livekit/protocol/rpc"
"github.com/livekit/protocol/utils"
)
// A rooms service that supports a single node
@@ -41,6 +42,7 @@ type RoomService struct {
router routing.MessageRouter
roomAllocator RoomAllocator
roomStore ServiceStore
agentClient rtc.AgentClient
egressLauncher rtc.EgressLauncher
topicFormatter rpc.TopicFormatter
roomClient rpc.TypedRoomClient
@@ -54,6 +56,7 @@ func NewRoomService(
router routing.MessageRouter,
roomAllocator RoomAllocator,
serviceStore ServiceStore,
agentClient rtc.AgentClient,
egressLauncher rtc.EgressLauncher,
topicFormatter rpc.TopicFormatter,
roomClient rpc.TypedRoomClient,
@@ -66,6 +69,7 @@ func NewRoomService(
router: router,
roomAllocator: roomAllocator,
roomStore: serviceStore,
agentClient: agentClient,
egressLauncher: egressLauncher,
topicFormatter: topicFormatter,
roomClient: roomClient,
@@ -112,14 +116,23 @@ func (s *RoomService) CreateRoom(ctx context.Context, req *livekit.CreateRoomReq
return nil, err
}
if created && req.Egress != nil && req.Egress.Room != nil {
egress := &rpc.StartEgressRequest{
Request: &rpc.StartEgressRequest_RoomComposite{
RoomComposite: req.Egress.Room,
},
RoomId: rm.Sid,
if created {
if s.agentClient != nil {
s.agentClient.JobRequest(ctx, &livekit.Job{
Id: utils.NewGuid("JR_"),
Type: livekit.JobType_JT_ROOM,
Room: rm,
})
}
if req.Egress != nil && req.Egress.Room != nil {
egress := &rpc.StartEgressRequest{
Request: &rpc.StartEgressRequest_RoomComposite{
RoomComposite: req.Egress.Room,
},
RoomId: rm.Sid,
}
_, err = s.egressLauncher.StartEgress(ctx, egress)
}
_, err = s.egressLauncher.StartEgress(ctx, egress)
}
return rm, err
@@ -427,7 +440,7 @@ func (s *RoomService) UpdateRoomMetadata(ctx context.Context, req *livekit.Updat
// no one has joined the room, would not have been created on an RTC node.
// in this case, we'd want to run create again
_, _, err = s.roomAllocator.CreateRoom(ctx, &livekit.CreateRoomRequest{
room, created, err := s.roomAllocator.CreateRoom(ctx, &livekit.CreateRoomRequest{
Name: req.Room,
Metadata: req.Metadata,
})
@@ -465,6 +478,14 @@ func (s *RoomService) UpdateRoomMetadata(ctx context.Context, req *livekit.Updat
return nil, err
}
if created && s.agentClient != nil {
s.agentClient.JobRequest(ctx, &livekit.Job{
Id: utils.NewGuid("JR_"),
Type: livekit.JobType_JT_ROOM,
Room: room,
})
}
return room, nil
}