feat: 自动建立实时监看媒体路径 (#51)
This commit is contained in:
@@ -24,22 +24,35 @@ type Profile struct {
|
|||||||
Verification rtsp.Result `json:"verification"`
|
Verification rtsp.Result `json:"verification"`
|
||||||
}
|
}
|
||||||
type Result struct {
|
type Result struct {
|
||||||
DeviceID string `json:"device_id"`
|
DeviceID string `json:"device_id"`
|
||||||
Address string `json:"address"`
|
Address string `json:"address"`
|
||||||
Status string `json:"status"`
|
Status string `json:"status"`
|
||||||
Detail string `json:"detail"`
|
Detail string `json:"detail"`
|
||||||
Profiles []Profile `json:"profiles"`
|
Profiles []Profile `json:"profiles"`
|
||||||
CheckedAt time.Time `json:"checked_at"`
|
MediaStatus string `json:"media_status,omitempty"`
|
||||||
|
MediaDetail string `json:"media_detail,omitempty"`
|
||||||
|
CheckedAt time.Time `json:"checked_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MediaOutcome struct {
|
||||||
|
Status string
|
||||||
|
Detail string
|
||||||
|
}
|
||||||
|
|
||||||
|
type ReadyHandler func(context.Context, identity.Principal, Result) MediaOutcome
|
||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
onvif onvif.Client
|
onvif onvif.Client
|
||||||
rtsp rtsp.Verifier
|
rtsp rtsp.Verifier
|
||||||
discoveryIP string
|
discoveryIP string
|
||||||
discoveryTimeout time.Duration
|
discoveryTimeout time.Duration
|
||||||
store Store
|
store Store
|
||||||
|
readyHandler ReadyHandler
|
||||||
now func() time.Time
|
now func() time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Service) SetReadyHandler(handler ReadyHandler) { s.readyHandler = handler }
|
||||||
|
|
||||||
func NewService(client onvif.Client, verifier rtsp.Verifier, discoveryIP string, stores ...Store) *Service {
|
func NewService(client onvif.Client, verifier rtsp.Verifier, discoveryIP string, stores ...Store) *Service {
|
||||||
var store Store = NewMemoryStore()
|
var store Store = NewMemoryStore()
|
||||||
if len(stores) > 0 && stores[0] != nil {
|
if len(stores) > 0 && stores[0] != nil {
|
||||||
@@ -106,6 +119,14 @@ func (s *Service) Probe(ctx context.Context, actor identity.Principal, deviceID,
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if s.readyHandler != nil {
|
||||||
|
outcome := s.readyHandler(ctx, actor, result)
|
||||||
|
result.MediaStatus = outcome.Status
|
||||||
|
result.MediaDetail = outcome.Detail
|
||||||
|
if err := s.store.Save(ctx, result); err != nil {
|
||||||
|
return Result{}, err
|
||||||
|
}
|
||||||
|
}
|
||||||
identity.RecordAudit(ctx, actor.UserID, "admission.probe", deviceID, "success", map[string]any{"profile_count": len(items), "status": status})
|
identity.RecordAudit(ctx, actor.UserID, "admission.probe", deviceID, "success", map[string]any{"profile_count": len(items), "status": status})
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user