fix: add push proxy

This commit is contained in:
langhuihui
2024-12-23 09:24:13 +08:00
parent 16d8f00e85
commit ebade42c73
6 changed files with 65 additions and 55 deletions

5
.gitignore vendored
View File

@@ -13,5 +13,8 @@ bin
*.flv *.flv
pullcf.yaml pullcf.yaml
admin.zip admin.zip
example/default/default
__debug* __debug*
.cursorrules
example/default/*
!example/default/main.go
!example/default/config.yaml

80
api.go
View File

@@ -793,26 +793,29 @@ func (s *Server) ModifyConfig(_ context.Context, req *pb.ModifyConfigRequest) (r
func (s *Server) GetPullProxyList(ctx context.Context, req *emptypb.Empty) (res *pb.PullProxyListResponse, err error) { func (s *Server) GetPullProxyList(ctx context.Context, req *emptypb.Empty) (res *pb.PullProxyListResponse, err error) {
res = &pb.PullProxyListResponse{} res = &pb.PullProxyListResponse{}
for device := range s.PullProxies.Range { s.PullProxies.Call(func() error {
res.Data = append(res.Data, &pb.PullProxyInfo{ for device := range s.PullProxies.Range {
Name: device.Name, res.Data = append(res.Data, &pb.PullProxyInfo{
CreateTime: timestamppb.New(device.CreatedAt), Name: device.Name,
UpdateTime: timestamppb.New(device.UpdatedAt), CreateTime: timestamppb.New(device.CreatedAt),
Type: device.Type, UpdateTime: timestamppb.New(device.UpdatedAt),
PullURL: device.URL, Type: device.Type,
ParentID: uint32(device.ParentID), PullURL: device.URL,
Status: uint32(device.Status), ParentID: uint32(device.ParentID),
ID: uint32(device.ID), Status: uint32(device.Status),
PullOnStart: device.PullOnStart, ID: uint32(device.ID),
StopOnIdle: device.StopOnIdle, PullOnStart: device.PullOnStart,
Audio: device.Audio, StopOnIdle: device.StopOnIdle,
RecordPath: device.Record.FilePath, Audio: device.Audio,
RecordFragment: durationpb.New(device.Record.Fragment), RecordPath: device.Record.FilePath,
Description: device.Description, RecordFragment: durationpb.New(device.Record.Fragment),
Rtt: uint32(device.RTT.Milliseconds()), Description: device.Description,
StreamPath: device.GetStreamPath(), Rtt: uint32(device.RTT.Milliseconds()),
}) StreamPath: device.GetStreamPath(),
} })
}
return nil
})
return return
} }
@@ -1072,23 +1075,26 @@ func (s *Server) SetStreamAlias(ctx context.Context, req *pb.SetStreamAliasReque
func (s *Server) GetPushProxyList(ctx context.Context, req *emptypb.Empty) (res *pb.PushProxyListResponse, err error) { func (s *Server) GetPushProxyList(ctx context.Context, req *emptypb.Empty) (res *pb.PushProxyListResponse, err error) {
res = &pb.PushProxyListResponse{} res = &pb.PushProxyListResponse{}
for device := range s.PushProxies.Range { s.PushProxies.Call(func() error {
res.Data = append(res.Data, &pb.PushProxyInfo{ for device := range s.PushProxies.Range {
Name: device.Name, res.Data = append(res.Data, &pb.PushProxyInfo{
CreateTime: timestamppb.New(device.CreatedAt), Name: device.Name,
UpdateTime: timestamppb.New(device.UpdatedAt), CreateTime: timestamppb.New(device.CreatedAt),
Type: device.Type, UpdateTime: timestamppb.New(device.UpdatedAt),
PushURL: device.URL, Type: device.Type,
ParentID: uint32(device.ParentID), PushURL: device.URL,
Status: uint32(device.Status), ParentID: uint32(device.ParentID),
ID: uint32(device.ID), Status: uint32(device.Status),
PushOnStart: device.PushOnStart, ID: uint32(device.ID),
Audio: device.Audio, PushOnStart: device.PushOnStart,
Description: device.Description, Audio: device.Audio,
Rtt: uint32(device.RTT.Milliseconds()), Description: device.Description,
StreamPath: device.GetStreamPath(), Rtt: uint32(device.RTT.Milliseconds()),
}) StreamPath: device.GetStreamPath(),
} })
}
return nil
})
return return
} }

View File

@@ -30,6 +30,11 @@ func (p *PushJob) GetKey() string {
func (p *PushJob) Init(pusher IPusher, plugin *Plugin, streamPath string, conf config.Push, subConf *config.Subscribe) *PushJob { func (p *PushJob) Init(pusher IPusher, plugin *Plugin, streamPath string, conf config.Push, subConf *config.Subscribe) *PushJob {
p.Connection.Init(plugin, streamPath, conf.URL, conf.Proxy, http.Header(conf.Header)) p.Connection.Init(plugin, streamPath, conf.URL, conf.Proxy, http.Header(conf.Header))
p.pusher = pusher p.pusher = pusher
if subConf == nil {
conf := plugin.config.Subscribe
subConf = &conf
}
subConf.SubType = SubscribeTypePush
p.SubConf = subConf p.SubConf = subConf
p.SetDescriptions(task.Description{ p.SetDescriptions(task.Description{
"plugin": plugin.Meta.Name, "plugin": plugin.Meta.Name,
@@ -43,13 +48,7 @@ func (p *PushJob) Init(pusher IPusher, plugin *Plugin, streamPath string, conf c
} }
func (p *PushJob) Subscribe() (err error) { func (p *PushJob) Subscribe() (err error) {
if p.SubConf != nil { p.Subscriber, err = p.Plugin.SubscribeWithConfig(p.pusher.GetTask().Context, p.StreamPath, *p.SubConf)
p.SubConf.SubType = SubscribeTypePush
p.Subscriber, err = p.Plugin.SubscribeWithConfig(p.pusher.GetTask().Context, p.StreamPath, *p.SubConf)
} else {
p.SubConf = &config.Subscribe{SubType: SubscribeTypePush}
p.Subscriber, err = p.Plugin.Subscribe(p.pusher.GetTask().Context, p.StreamPath)
}
return return
} }

View File

@@ -81,13 +81,8 @@ func (p *RecordJob) GetKey() string {
} }
func (p *RecordJob) Subscribe() (err error) { func (p *RecordJob) Subscribe() (err error) {
if p.SubConf != nil {
p.SubConf.SubType = SubscribeTypeVod p.Subscriber, err = p.Plugin.SubscribeWithConfig(p.recorder.GetTask().Context, p.StreamPath, *p.SubConf)
p.Subscriber, err = p.Plugin.SubscribeWithConfig(p.recorder.GetTask().Context, p.StreamPath, *p.SubConf)
} else {
p.SubConf = &config.Subscribe{SubType: SubscribeTypeVod}
p.Subscriber, err = p.Plugin.SubscribeWithConfig(p.recorder.GetTask().Context, p.StreamPath, *p.SubConf)
}
return return
} }
@@ -97,6 +92,11 @@ func (p *RecordJob) Init(recorder IRecorder, plugin *Plugin, streamPath string,
p.Append = conf.Append p.Append = conf.Append
p.FilePath = conf.FilePath p.FilePath = conf.FilePath
p.StreamPath = streamPath p.StreamPath = streamPath
if subConf == nil {
conf := p.Plugin.config.Subscribe
subConf = &conf
}
subConf.SubType = SubscribeTypeVod
p.SubConf = subConf p.SubConf = subConf
p.recorder = recorder p.recorder = recorder
p.SetDescriptions(task.Description{ p.SetDescriptions(task.Description{

View File

@@ -285,6 +285,7 @@ func (s *Server) Start() (err error) {
s.AddTask(&s.Pushs) s.AddTask(&s.Pushs)
s.AddTask(&s.Transforms) s.AddTask(&s.Transforms)
s.AddTask(&s.PullProxies) s.AddTask(&s.PullProxies)
s.AddTask(&s.PushProxies)
promReg := prometheus.NewPedanticRegistry() promReg := prometheus.NewPedanticRegistry()
promReg.MustRegister(s) promReg.MustRegister(s)
for _, plugin := range plugins { for _, plugin := range plugins {

View File

@@ -68,8 +68,9 @@ func (r *DefaultTransformer) GetTransformJob() *TransformJob {
} }
func (p *TransformJob) Subscribe() (err error) { func (p *TransformJob) Subscribe() (err error) {
p.Plugin.config.SubType = SubscribeTypeTransform subConfig := p.Plugin.config.Subscribe
p.Subscriber, err = p.Plugin.Subscribe(p.Transformer, p.StreamPath) subConfig.SubType = SubscribeTypeTransform
p.Subscriber, err = p.Plugin.SubscribeWithConfig(p.Transformer, p.StreamPath, subConfig)
if err == nil { if err == nil {
p.Transformer.Depend(p.Subscriber) p.Transformer.Depend(p.Subscriber)
} }