From 04e2598be0948ba896f73628d0f2988fc1b17d6f Mon Sep 17 00:00:00 2001 From: ila <2+ila@noreply.git.ilapage.cn> Date: Thu, 13 Aug 2026 12:42:10 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=87=AA=E5=8A=A8=E5=BB=BA=E7=AB=8B?= =?UTF-8?q?=E5=AE=9E=E6=97=B6=E7=9B=91=E7=9C=8B=E5=AA=92=E4=BD=93=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=20(#51)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sense/server/app/sense/media/service.go | 33 ++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/Sense/server/app/sense/media/service.go b/Sense/server/app/sense/media/service.go index 8197930..b2afb49 100644 --- a/Sense/server/app/sense/media/service.go +++ b/Sense/server/app/sense/media/service.go @@ -21,7 +21,33 @@ type Service struct { } func NewService(store Store, process mediamtx.Process, controller mediamtx.Controller) *Service { - return &Service{store: store, process: process, controller: controller, profile: admission.VerifiedProfile, credential: device.ReadCredential, now: time.Now} + return &Service{store: store, process: process, controller: controller, profile: admission.VerifiedProfile, credential: device.ReadRTSPCredential, now: time.Now} +} + +func (s *Service) ConfigureProfiles(ctx context.Context, actor identity.Principal, result admission.Result) admission.MediaOutcome { + configured := 0 + ready := 0 + for _, profile := range result.Profiles { + if profile.Verification.Status != "ready" { + continue + } + configured++ + route, err := s.Configure(ctx, actor, result.DeviceID, profile.Token) + if err != nil { + continue + } + route, err = s.Reconcile(ctx, actor, route.ID) + if err == nil && route.Actual == "ready" { + ready++ + } + } + if configured == 0 { + return admission.MediaOutcome{Status: "needs_attention", Detail: "未找到可用码流,请检查接入结果"} + } + if ready == configured { + return admission.MediaOutcome{Status: "ready", Detail: "视频已进入实时监看"} + } + return admission.MediaOutcome{Status: "needs_attention", Detail: "摄像机已接入,媒体服务未就绪,请到视频服务查看并重试"} } func (s *Service) Configure(ctx context.Context, actor identity.Principal, deviceID, profileToken string) (Route, error) { if _, err := s.profile(deviceID, profileToken); err != nil { @@ -55,7 +81,7 @@ func (s *Service) Reconcile(ctx context.Context, actor identity.Principal, id st } if err := s.process.Start(ctx); err != nil { route.Actual = "process_failed" - route.Detail = err.Error() + route.Detail = "媒体进程未启动,请检查视频服务配置" route.Version++ route.UpdatedAt = s.now().UTC() _ = s.store.Save(ctx, route) @@ -72,7 +98,7 @@ func (s *Service) Reconcile(ctx context.Context, actor identity.Principal, id st source := mediamtx.Source{Path: route.Path, URI: profile.StreamURI, Username: credential.Username, Password: credential.Password} if err := s.controller.Apply(ctx, source); err != nil { route.Actual = "apply_failed" - route.Detail = err.Error() + route.Detail = "媒体路径配置失败,请检查视频服务" route.Version++ route.UpdatedAt = s.now().UTC() _ = s.store.Save(ctx, route) @@ -138,3 +164,4 @@ func safe(value string) string { return '_' }, value) } +