@@ -1,178 +0,0 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/recording"
|
||||
"github.com/livekit/protocol/utils"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/telemetry"
|
||||
)
|
||||
|
||||
type RecordingService struct {
|
||||
bus utils.MessageBus
|
||||
telemetry telemetry.TelemetryService
|
||||
shutdown chan struct{}
|
||||
}
|
||||
|
||||
func NewRecordingService(mb utils.MessageBus, telemetry telemetry.TelemetryService) *RecordingService {
|
||||
return &RecordingService{
|
||||
bus: mb,
|
||||
telemetry: telemetry,
|
||||
shutdown: make(chan struct{}, 1),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *RecordingService) Start() {
|
||||
if s.bus != nil {
|
||||
go s.resultsWorker()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *RecordingService) Stop() {
|
||||
s.shutdown <- struct{}{}
|
||||
}
|
||||
|
||||
// RecordingService is deprecated, use EgressService instead
|
||||
func (s *RecordingService) StartRecording(ctx context.Context, req *livekit.StartRecordingRequest) (*livekit.StartRecordingResponse, error) {
|
||||
if err := EnsureRecordPermission(ctx); err != nil {
|
||||
return nil, twirpAuthError(err)
|
||||
}
|
||||
if s.bus == nil {
|
||||
return nil, errors.New("recording not configured (redis required)")
|
||||
}
|
||||
|
||||
// reserve a recorder
|
||||
recordingID, err := recording.ReserveRecorder(s.bus)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// start the recording
|
||||
err = recording.RPC(ctx, s.bus, recordingID, &livekit.RecordingRequest{
|
||||
Request: &livekit.RecordingRequest_Start{
|
||||
Start: req,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ri := &livekit.RecordingInfo{
|
||||
Id: recordingID,
|
||||
Active: true,
|
||||
}
|
||||
|
||||
switch template := req.Input.(type) {
|
||||
case *livekit.StartRecordingRequest_Template:
|
||||
ri.RoomName = template.Template.RoomName
|
||||
}
|
||||
|
||||
logger.Debugw("recording started", "recordingID", recordingID)
|
||||
s.telemetry.RecordingStarted(ctx, ri)
|
||||
|
||||
return &livekit.StartRecordingResponse{RecordingId: recordingID}, nil
|
||||
}
|
||||
|
||||
// RecordingService is deprecated, use EgressService instead
|
||||
func (s *RecordingService) AddOutput(ctx context.Context, req *livekit.AddOutputRequest) (*emptypb.Empty, error) {
|
||||
if err := EnsureRecordPermission(ctx); err != nil {
|
||||
return nil, twirpAuthError(err)
|
||||
}
|
||||
if s.bus == nil {
|
||||
return nil, errors.New("recording not configured (redis required)")
|
||||
}
|
||||
|
||||
err := recording.RPC(ctx, s.bus, req.RecordingId, &livekit.RecordingRequest{
|
||||
Request: &livekit.RecordingRequest_AddOutput{
|
||||
AddOutput: req,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &emptypb.Empty{}, nil
|
||||
}
|
||||
|
||||
// RecordingService is deprecated, use EgressService instead
|
||||
func (s *RecordingService) RemoveOutput(ctx context.Context, req *livekit.RemoveOutputRequest) (*emptypb.Empty, error) {
|
||||
if err := EnsureRecordPermission(ctx); err != nil {
|
||||
return nil, twirpAuthError(err)
|
||||
}
|
||||
if s.bus == nil {
|
||||
return nil, errors.New("recording not configured (redis required)")
|
||||
}
|
||||
|
||||
err := recording.RPC(ctx, s.bus, req.RecordingId, &livekit.RecordingRequest{
|
||||
Request: &livekit.RecordingRequest_RemoveOutput{
|
||||
RemoveOutput: req,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &emptypb.Empty{}, nil
|
||||
}
|
||||
|
||||
// RecordingService is deprecated, use EgressService instead
|
||||
func (s *RecordingService) EndRecording(ctx context.Context, req *livekit.EndRecordingRequest) (*emptypb.Empty, error) {
|
||||
if err := EnsureRecordPermission(ctx); err != nil {
|
||||
return nil, twirpAuthError(err)
|
||||
}
|
||||
if s.bus == nil {
|
||||
return nil, errors.New("recording not configured (redis required)")
|
||||
}
|
||||
|
||||
err := recording.RPC(ctx, s.bus, req.RecordingId, &livekit.RecordingRequest{
|
||||
Request: &livekit.RecordingRequest_End{
|
||||
End: req,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &emptypb.Empty{}, nil
|
||||
}
|
||||
|
||||
func (s *RecordingService) resultsWorker() {
|
||||
sub, err := s.bus.SubscribeQueue(context.Background(), recording.ResultChannel)
|
||||
if err != nil {
|
||||
logger.Errorw("failed to subscribe to results channel", err)
|
||||
return
|
||||
}
|
||||
|
||||
resChan := sub.Channel()
|
||||
for {
|
||||
select {
|
||||
case msg := <-resChan:
|
||||
b := sub.Payload(msg)
|
||||
|
||||
res := &livekit.RecordingInfo{}
|
||||
if err = proto.Unmarshal(b, res); err != nil {
|
||||
logger.Errorw("failed to read results", err)
|
||||
continue
|
||||
}
|
||||
|
||||
// log results
|
||||
values := []interface{}{"recordingID", res.Id}
|
||||
if res.Error != "" {
|
||||
values = append(values, "error", res.Error)
|
||||
}
|
||||
logger.Debugw("recording ended", values...)
|
||||
|
||||
s.telemetry.RecordingEnded(context.Background(), res)
|
||||
case <-s.shutdown:
|
||||
_ = sub.Close()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,6 @@ import (
|
||||
type LivekitServer struct {
|
||||
config *config.Config
|
||||
egressService *EgressService
|
||||
recService *RecordingService
|
||||
rtcService *RTCService
|
||||
httpServer *http.Server
|
||||
promServer *http.Server
|
||||
@@ -44,7 +43,6 @@ type LivekitServer struct {
|
||||
func NewLivekitServer(conf *config.Config,
|
||||
roomService livekit.RoomService,
|
||||
egressService *EgressService,
|
||||
recService *RecordingService,
|
||||
rtcService *RTCService,
|
||||
keyProvider auth.KeyProvider,
|
||||
router routing.Router,
|
||||
@@ -55,7 +53,6 @@ func NewLivekitServer(conf *config.Config,
|
||||
s = &LivekitServer{
|
||||
config: conf,
|
||||
egressService: egressService,
|
||||
recService: recService,
|
||||
rtcService: rtcService,
|
||||
router: router,
|
||||
roomManager: roomManager,
|
||||
@@ -82,7 +79,6 @@ func NewLivekitServer(conf *config.Config,
|
||||
|
||||
roomServer := livekit.NewRoomServiceServer(roomService)
|
||||
egressServer := livekit.NewEgressServer(egressService)
|
||||
recServer := livekit.NewRecordingServiceServer(recService)
|
||||
|
||||
mux := http.NewServeMux()
|
||||
if conf.Development {
|
||||
@@ -93,7 +89,6 @@ func NewLivekitServer(conf *config.Config,
|
||||
}
|
||||
mux.Handle(roomServer.PathPrefix(), roomServer)
|
||||
mux.Handle(egressServer.PathPrefix(), egressServer)
|
||||
mux.Handle(recServer.PathPrefix(), recServer)
|
||||
mux.Handle("/rtc", rtcService)
|
||||
mux.HandleFunc("/rtc/validate", rtcService.Validate)
|
||||
mux.HandleFunc("/", s.healthCheck)
|
||||
@@ -153,7 +148,6 @@ func (s *LivekitServer) Start() error {
|
||||
}
|
||||
|
||||
s.egressService.Start()
|
||||
s.recService.Start()
|
||||
|
||||
// ensure we could listen
|
||||
ln, err := net.Listen("tcp", s.httpServer.Addr)
|
||||
@@ -221,7 +215,6 @@ func (s *LivekitServer) Start() error {
|
||||
|
||||
s.roomManager.Stop()
|
||||
s.egressService.Stop()
|
||||
s.recService.Stop()
|
||||
|
||||
close(s.closedChan)
|
||||
return nil
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"github.com/livekit/protocol/egress"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"github.com/livekit/protocol/webhook"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/clientconfiguration"
|
||||
@@ -31,7 +30,6 @@ func InitializeServer(conf *config.Config, currentNode routing.LocalNode) (*Live
|
||||
wire.Build(
|
||||
getNodeID,
|
||||
createRedisClient,
|
||||
createMessageBus,
|
||||
createStore,
|
||||
wire.Bind(new(ServiceStore), new(ObjectStore)),
|
||||
createKeyProvider,
|
||||
@@ -45,7 +43,6 @@ func InitializeServer(conf *config.Config, currentNode routing.LocalNode) (*Live
|
||||
telemetry.NewTelemetryService,
|
||||
egress.NewRedisRPCClient,
|
||||
NewEgressService,
|
||||
NewRecordingService,
|
||||
NewRoomAllocator,
|
||||
NewRoomService,
|
||||
NewRTCService,
|
||||
@@ -158,13 +155,6 @@ func createRedisClient(conf *config.Config) (*redis.Client, error) {
|
||||
return rc, nil
|
||||
}
|
||||
|
||||
func createMessageBus(rc *redis.Client) utils.MessageBus {
|
||||
if rc == nil {
|
||||
return nil
|
||||
}
|
||||
return utils.NewRedisMessageBus(rc)
|
||||
}
|
||||
|
||||
func createStore(rc *redis.Client) ObjectStore {
|
||||
if rc != nil {
|
||||
return NewRedisStore(rc)
|
||||
|
||||
+1
-11
@@ -19,7 +19,6 @@ import (
|
||||
"github.com/livekit/protocol/egress"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"github.com/livekit/protocol/webhook"
|
||||
"github.com/pkg/errors"
|
||||
"gopkg.in/yaml.v3"
|
||||
@@ -61,8 +60,6 @@ func InitializeServer(conf *config.Config, currentNode routing.LocalNode) (*Live
|
||||
analyticsService := telemetry.NewAnalyticsService(conf, currentNode)
|
||||
telemetryService := telemetry.NewTelemetryService(notifier, analyticsService)
|
||||
egressService := NewEgressService(rpcClient, objectStore, roomService, telemetryService)
|
||||
messageBus := createMessageBus(client)
|
||||
recordingService := NewRecordingService(messageBus, telemetryService)
|
||||
rtcService := NewRTCService(conf, roomAllocator, objectStore, router, currentNode)
|
||||
clientConfigurationManager := createClientConfiguration()
|
||||
roomManager, err := NewLocalRoomManager(conf, objectStore, currentNode, router, telemetryService, clientConfigurationManager)
|
||||
@@ -74,7 +71,7 @@ func InitializeServer(conf *config.Config, currentNode routing.LocalNode) (*Live
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
livekitServer, err := NewLivekitServer(conf, roomService, egressService, recordingService, rtcService, keyProvider, router, roomManager, server, currentNode)
|
||||
livekitServer, err := NewLivekitServer(conf, roomService, egressService, rtcService, keyProvider, router, roomManager, server, currentNode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -184,13 +181,6 @@ func createRedisClient(conf *config.Config) (*redis.Client, error) {
|
||||
return rc, nil
|
||||
}
|
||||
|
||||
func createMessageBus(rc *redis.Client) utils.MessageBus {
|
||||
if rc == nil {
|
||||
return nil
|
||||
}
|
||||
return utils.NewRedisMessageBus(rc)
|
||||
}
|
||||
|
||||
func createStore(rc *redis.Client) ObjectStore {
|
||||
if rc != nil {
|
||||
return NewRedisStore(rc)
|
||||
|
||||
Reference in New Issue
Block a user