From 0ef8af021f876136acc5eb20d43af584375bbaf6 Mon Sep 17 00:00:00 2001 From: imbytecat Date: Mon, 26 Aug 2024 15:21:47 +0800 Subject: [PATCH] =?UTF-8?q?feat(onvif):=20=E6=B7=BB=E5=8A=A0=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E5=AD=98=E5=82=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- router/handler/onvif/notification.go | 10 ++++++++++ router/handler/onvif/subscription.go | 9 +++++---- router/router.go | 5 +++++ service/onvif/event.go | 2 ++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/router/handler/onvif/notification.go b/router/handler/onvif/notification.go index b6b13c5..126a330 100644 --- a/router/handler/onvif/notification.go +++ b/router/handler/onvif/notification.go @@ -1 +1,11 @@ package onvif + +import ( + "github.com/gin-gonic/gin" + "onvif-agent/response" + "onvif-agent/service/onvif" +) + +func GetNotifications(c *gin.Context) { + response.NewResponse().WithData(onvif.Notifications).Send(c) +} diff --git a/router/handler/onvif/subscription.go b/router/handler/onvif/subscription.go index b1d0d1a..c5ab017 100644 --- a/router/handler/onvif/subscription.go +++ b/router/handler/onvif/subscription.go @@ -43,10 +43,11 @@ func NotifyCallback(c *gin.Context) { return } - // TODO: handle notifications - for _, msg := range envelope.Body.Content.(*event.Notify).NotificationMessage { - log.Printf("Topic: %s, Message: %s", msg.Topic.TopicKinds, msg.Message.Message) - } + onvif.Notifications[xaddr] = append(onvif.Notifications[xaddr], notify.NotificationMessage...) + + //for _, msg := range envelope.Body.Content.(*event.Notify).NotificationMessage { + // log.Printf("Topic: %s, Message: %s", msg.Topic.TopicKinds, msg.Message.Message) + //} response.NewResponse().Success().Send(c) } diff --git a/router/router.go b/router/router.go index e8ee2c4..03fdd5f 100644 --- a/router/router.go +++ b/router/router.go @@ -25,6 +25,11 @@ func SetupRoutes(r *gin.Engine) { subscriptionGroup.POST("/:xaddr", onvif.CreateSubscription) subscriptionGroup.POST("/:xaddr/callback", onvif.NotifyCallback) } + + notificationGroup := onvifGroup.Group("/notifications") + { + notificationGroup.GET("/", onvif.GetNotifications) + } } zabbixGroup := r.Group("/zabbix") diff --git a/service/onvif/event.go b/service/onvif/event.go index fe2eea0..268b842 100644 --- a/service/onvif/event.go +++ b/service/onvif/event.go @@ -5,6 +5,8 @@ import ( "github.com/IOTechSystems/onvif/xsd" ) +var Notifications = make(map[string][]event.NotificationMessage) + func (c *Session) EventSubscribe( consumerAddress event.AttributedURIType, terminationTime xsd.String, // PT60S