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