feat(router): 参数化 callback URL

This commit is contained in:
2024-08-22 12:07:45 +08:00
parent 49fb4b1f91
commit 66254725df
4 changed files with 22 additions and 5 deletions

View File

@ -12,7 +12,8 @@ import (
func CreateEventSubscription(c *gin.Context) {
xaddr := c.Param("xaddr")
callbackURL := event.AttributedURIType(fmt.Sprintf("%s/subscriptions/callback", config.Conf.App.URL))
callbackURL := event.AttributedURIType(fmt.Sprintf("%s/onvif/subscriptions/%s/callback", config.Conf.App.URL, xaddr))
log.Printf("CreateEventSubscription callback URL: %s", callbackURL)
result, err := conns[xaddr].SubscribeEvents(callbackURL, "PT60S")
if err != nil {
c.JSON(http.StatusServiceUnavailable, gin.H{
@ -25,6 +26,9 @@ func CreateEventSubscription(c *gin.Context) {
}
func EventNotifyCallback(c *gin.Context) {
xaddr := c.Param("xaddr")
log.Printf("EventNotifyCallback from: %s", xaddr)
var notify event.Notify
envelope := gosoap.NewSOAPEnvelope(&notify)
if err := c.ShouldBindXML(&envelope); err != nil {
@ -34,7 +38,7 @@ func EventNotifyCallback(c *gin.Context) {
// TODO: handle notifications
for _, msg := range envelope.Body.Content.(*event.Notify).NotificationMessage {
log.Println(msg.Topic.TopicKinds, msg.Message.Message)
log.Printf("Topic: %s, Message: %s", msg.Topic.TopicKinds, msg.Message.Message)
}
c.JSON(http.StatusOK, gin.H{"message": "OK"})