feat: 自动建立实时监看媒体路径 (#51)
This commit is contained in:
@@ -24,22 +24,35 @@ type Profile struct {
|
||||
Verification rtsp.Result `json:"verification"`
|
||||
}
|
||||
type Result struct {
|
||||
DeviceID string `json:"device_id"`
|
||||
Address string `json:"address"`
|
||||
Status string `json:"status"`
|
||||
Detail string `json:"detail"`
|
||||
Profiles []Profile `json:"profiles"`
|
||||
CheckedAt time.Time `json:"checked_at"`
|
||||
DeviceID string `json:"device_id"`
|
||||
Address string `json:"address"`
|
||||
Status string `json:"status"`
|
||||
Detail string `json:"detail"`
|
||||
Profiles []Profile `json:"profiles"`
|
||||
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 {
|
||||
onvif onvif.Client
|
||||
rtsp rtsp.Verifier
|
||||
discoveryIP string
|
||||
discoveryTimeout time.Duration
|
||||
store Store
|
||||
readyHandler ReadyHandler
|
||||
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 {
|
||||
var store Store = NewMemoryStore()
|
||||
if len(stores) > 0 && stores[0] != nil {
|
||||
@@ -106,6 +119,14 @@ func (s *Service) Probe(ctx context.Context, actor identity.Principal, deviceID,
|
||||
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})
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user