refactor: 迁移 service 代码逻辑

This commit is contained in:
2024-08-26 14:50:46 +08:00
parent de3667f957
commit 219116c961
5 changed files with 37 additions and 27 deletions

View File

@ -3,12 +3,12 @@ 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"
"onvif-agent/service/onvif"
)
func CreateSubscription(c *gin.Context) {
@ -16,7 +16,7 @@ func CreateSubscription(c *gin.Context) {
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]
conn := onvif.Sessions[xaddr]
if conn == nil {
response.NewResponse().Fail("Connection not found").WithCode(http.StatusNotFound).Send(c)
return
@ -30,21 +30,3 @@ func CreateSubscription(c *gin.Context) {
response.NewResponse().Success().WithData(result).Send(c)
}
func NotifyCallback(c *gin.Context) {
//xaddr := c.Param("xaddr")
var notify event.Notify
envelope := gosoap.NewSOAPEnvelope(&notify)
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)
}