package onvif import ( "fmt" "github.com/IOTechSystems/onvif/event" "github.com/IOTechSystems/onvif/gosoap" "github.com/gin-gonic/gin" "log" "net/http" "onvif-agent/config" "onvif-agent/response" ) func CreateSubscription(c *gin.Context) { xaddr := c.Param("xaddr") callbackURL := event.AttributedURIType(fmt.Sprintf("%s/onvif/subscriptions/%s/callback", config.Config.App.URL, xaddr)) log.Printf("CreateSubscription callback URL: %s", callbackURL) conn := Sessions[xaddr] if conn == nil { response.NewResponse().Fail("Connection not found").WithCode(http.StatusNotFound).Send(c) return } result, err := conn.SubscribeEvents(callbackURL, "PT60S") if err != nil { response.NewResponse().Error(err).Send(c) return } response.NewResponse().Success().WithData(result).Send(c) } func NotifyCallback(c *gin.Context) { //xaddr := c.Param("xaddr") var notify event.Notify envelope := gosoap.NewSOAPEnvelope(¬ify) if err := c.ShouldBindXML(&envelope); err != nil { response.NewResponse().Error(err).WithCode(http.StatusBadRequest).Send(c) 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) } response.NewResponse().Success().Send(c) }