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

6
api.go
View File

@@ -793,6 +793,7 @@ 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{}
s.PullProxies.Call(func() error {
for device := range s.PullProxies.Range { for device := range s.PullProxies.Range {
res.Data = append(res.Data, &pb.PullProxyInfo{ res.Data = append(res.Data, &pb.PullProxyInfo{
Name: device.Name, Name: device.Name,
@@ -813,6 +814,8 @@ func (s *Server) GetPullProxyList(ctx context.Context, req *emptypb.Empty) (res
StreamPath: device.GetStreamPath(), StreamPath: device.GetStreamPath(),
}) })
} }
return nil
})
return return
} }
@@ -1072,6 +1075,7 @@ 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{}
s.PushProxies.Call(func() error {
for device := range s.PushProxies.Range { for device := range s.PushProxies.Range {
res.Data = append(res.Data, &pb.PushProxyInfo{ res.Data = append(res.Data, &pb.PushProxyInfo{
Name: device.Name, Name: device.Name,
@@ -1089,6 +1093,8 @@ func (s *Server) GetPushProxyList(ctx context.Context, req *emptypb.Empty) (res
StreamPath: device.GetStreamPath(), 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.SubConf.SubType = SubscribeTypePush
p.Subscriber, err = p.Plugin.SubscribeWithConfig(p.pusher.GetTask().Context, p.StreamPath, *p.SubConf) 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)
} }