mirror of
https://github.com/langhuihui/monibuca.git
synced 2025-11-02 20:14:01 +08:00
fix: update pull proxy
This commit is contained in:
24
api.go
24
api.go
@@ -897,7 +897,9 @@ func (s *Server) UpdatePullProxy(ctx context.Context, req *pb.PullProxyInfo) (re
|
|||||||
err = pkg.ErrNoDB
|
err = pkg.ErrNoDB
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
target := &PullProxy{}
|
target := &PullProxy{
|
||||||
|
server: s,
|
||||||
|
}
|
||||||
err = s.DB.First(target, req.ID).Error
|
err = s.DB.First(target, req.ID).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -937,12 +939,12 @@ func (s *Server) UpdatePullProxy(ctx context.Context, req *pb.PullProxyInfo) (re
|
|||||||
target.RTT = time.Duration(int(req.Rtt)) * time.Millisecond
|
target.RTT = time.Duration(int(req.Rtt)) * time.Millisecond
|
||||||
target.StreamPath = req.StreamPath
|
target.StreamPath = req.StreamPath
|
||||||
s.DB.Save(target)
|
s.DB.Save(target)
|
||||||
|
var needStopOld *PullProxy
|
||||||
s.PullProxies.Call(func() error {
|
s.PullProxies.Call(func() error {
|
||||||
if device, ok := s.PullProxies.Get(uint(req.ID)); ok {
|
if device, ok := s.PullProxies.Get(uint(req.ID)); ok {
|
||||||
if target.URL != device.URL || device.Audio != target.Audio || device.StreamPath != target.StreamPath || device.Record.FilePath != target.Record.FilePath || device.Record.Fragment != target.Record.Fragment {
|
if target.URL != device.URL || device.Audio != target.Audio || device.StreamPath != target.StreamPath || device.Record.FilePath != target.Record.FilePath || device.Record.Fragment != target.Record.Fragment {
|
||||||
device.Stop(task.ErrStopByUser)
|
device.Stop(task.ErrStopByUser)
|
||||||
device.WaitStopped()
|
needStopOld = device
|
||||||
s.PullProxies.Add(target)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if device.PullOnStart != target.PullOnStart && target.PullOnStart && device.Handler != nil && device.Status == PullProxyStatusOnline {
|
if device.PullOnStart != target.PullOnStart && target.PullOnStart && device.Handler != nil && device.Status == PullProxyStatusOnline {
|
||||||
@@ -955,6 +957,10 @@ func (s *Server) UpdatePullProxy(ctx context.Context, req *pb.PullProxyInfo) (re
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
if needStopOld != nil {
|
||||||
|
needStopOld.WaitStopped()
|
||||||
|
s.PullProxies.Add(target)
|
||||||
|
}
|
||||||
res = &pb.SuccessResponse{}
|
res = &pb.SuccessResponse{}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -1174,7 +1180,9 @@ func (s *Server) UpdatePushProxy(ctx context.Context, req *pb.PushProxyInfo) (re
|
|||||||
err = pkg.ErrNoDB
|
err = pkg.ErrNoDB
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
target := &PushProxy{}
|
target := &PushProxy{
|
||||||
|
server: s,
|
||||||
|
}
|
||||||
err = s.DB.First(target, req.ID).Error
|
err = s.DB.First(target, req.ID).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@@ -1211,12 +1219,12 @@ func (s *Server) UpdatePushProxy(ctx context.Context, req *pb.PushProxyInfo) (re
|
|||||||
target.RTT = time.Duration(int(req.Rtt)) * time.Millisecond
|
target.RTT = time.Duration(int(req.Rtt)) * time.Millisecond
|
||||||
target.StreamPath = req.StreamPath
|
target.StreamPath = req.StreamPath
|
||||||
s.DB.Save(target)
|
s.DB.Save(target)
|
||||||
|
var needStopOld *PushProxy
|
||||||
s.PushProxies.Call(func() error {
|
s.PushProxies.Call(func() error {
|
||||||
if device, ok := s.PushProxies.Get(uint(req.ID)); ok {
|
if device, ok := s.PushProxies.Get(uint(req.ID)); ok {
|
||||||
if target.URL != device.URL || device.Audio != target.Audio || device.StreamPath != target.StreamPath {
|
if target.URL != device.URL || device.Audio != target.Audio || device.StreamPath != target.StreamPath {
|
||||||
device.Stop(task.ErrStopByUser)
|
device.Stop(task.ErrStopByUser)
|
||||||
device.WaitStopped()
|
needStopOld = device
|
||||||
s.PushProxies.Add(target)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if device.PushOnStart != target.PushOnStart && target.PushOnStart && device.Handler != nil && device.Status == PushProxyStatusOnline {
|
if device.PushOnStart != target.PushOnStart && target.PushOnStart && device.Handler != nil && device.Status == PushProxyStatusOnline {
|
||||||
@@ -1228,6 +1236,10 @@ func (s *Server) UpdatePushProxy(ctx context.Context, req *pb.PushProxyInfo) (re
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
if needStopOld != nil {
|
||||||
|
needStopOld.WaitStopped()
|
||||||
|
s.PushProxies.Add(target)
|
||||||
|
}
|
||||||
res = &pb.SuccessResponse{}
|
res = &pb.SuccessResponse{}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,5 +174,7 @@ func (d *TCPPullProxy) Tick(any) {
|
|||||||
}
|
}
|
||||||
conn.Close()
|
conn.Close()
|
||||||
d.PullProxy.RTT = time.Since(startTime)
|
d.PullProxy.RTT = time.Since(startTime)
|
||||||
|
if d.PullProxy.Status == PullProxyStatusOffline {
|
||||||
d.PullProxy.ChangeStatus(PullProxyStatusOnline)
|
d.PullProxy.ChangeStatus(PullProxyStatusOnline)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -137,5 +137,7 @@ func (d *TCPPushProxy) Tick(any) {
|
|||||||
}
|
}
|
||||||
conn.Close()
|
conn.Close()
|
||||||
d.PushProxy.RTT = time.Since(startTime)
|
d.PushProxy.RTT = time.Since(startTime)
|
||||||
|
if d.PushProxy.Status == PushProxyStatusOffline {
|
||||||
d.PushProxy.ChangeStatus(PushProxyStatusOnline)
|
d.PushProxy.ChangeStatus(PushProxyStatusOnline)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user