33 lines
798 B
Go

package onvif
import (
"fmt"
"github.com/IOTechSystems/onvif/event"
"github.com/gin-gonic/gin"
"log"
"net/http"
"onvif-agent/config"
"onvif-agent/response"
"onvif-agent/service/onvif"
)
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 := onvif.Sessions[xaddr]
if conn == nil {
response.NewResponse().Fail("Connection not found").WithCode(http.StatusNotFound).Send(c)
return
}
result, err := conn.EventSubscribe(callbackURL, "PT60S")
if err != nil {
response.NewResponse().Error(err).Send(c)
return
}
response.NewResponse().Success().WithData(result).Send(c)
}