39 lines
927 B
Go
39 lines
927 B
Go
package onvif
|
|
|
|
import (
|
|
"github.com/IOTechSystems/onvif/event"
|
|
"github.com/IOTechSystems/onvif/gosoap"
|
|
"github.com/gin-gonic/gin"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
func CreateEventSubscription(c *gin.Context) {
|
|
xaddr := c.Param("xaddr")
|
|
// FIXME: 把参数变成传入的参数
|
|
result, err := conns[xaddr].SubscribeEvents("http://172.16.19.230:8080/events/callback", "PT60S")
|
|
if err != nil {
|
|
c.JSON(http.StatusServiceUnavailable, gin.H{
|
|
"message": err.Error(),
|
|
})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, result)
|
|
}
|
|
|
|
func EventNotifyCallback(c *gin.Context) {
|
|
var notify event.Notify
|
|
envelope := gosoap.NewSOAPEnvelope(¬ify)
|
|
if err := c.ShouldBindXML(&envelope); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
for _, msg := range envelope.Body.Content.(*event.Notify).NotificationMessage {
|
|
log.Println(msg.Topic.TopicKinds, msg.Message.Message)
|
|
}
|
|
|
|
c.String(http.StatusOK, "OK")
|
|
}
|