diff --git a/haivision/auth.go b/haivision/auth.go index 0ce8a65..dfb7127 100644 --- a/haivision/auth.go +++ b/haivision/auth.go @@ -30,7 +30,7 @@ Response } } */ -func (o *Haivision) InitSession(username string, password string) (*session.BaseResponseInitSession, error) { +func (o *haivisionSdk) InitSession(username string, password string) (*session.BaseResponseInitSession, error) { requestBody := &session.RequestInitSession{ Username: username, Password: password, @@ -78,7 +78,7 @@ Response ] */ -func (o *Haivision) GetDeviceInfo() (*[]device.ResponseDeviceInfo, error) { +func (o *haivisionSdk) GetDeviceInfo() (*[]device.ResponseDeviceInfo, error) { resp, err := o.restyGet(DEVICE_INFO, nil) if err != nil { return nil, err @@ -93,3 +93,15 @@ func (o *Haivision) GetDeviceInfo() (*[]device.ResponseDeviceInfo, error) { } // + +func (o *haivisionSdk) GetSessionInfo() (*session.ResponseSessionInfo, error) { + resp, err := o.restyGet(SESSION, nil) + if err != nil { + return nil, err + } + var obj session.ResponseSessionInfo + if err := json.Unmarshal(resp.Body(), &obj); err != nil { + return nil, err + } + return &obj, nil +} diff --git a/haivision/builder.go b/haivision/builder.go index 9653d7f..6973fde 100644 --- a/haivision/builder.go +++ b/haivision/builder.go @@ -9,9 +9,9 @@ import ( ) // Builder is used to build a new haivision client -func BuildHaivision(url string, debug bool, username string, password string, header *HeaderConfigurator, insecure *bool) (*Haivision, error) { +func BuildHaivision(url string, debug bool, username string, password string, header *HeaderConfigurator, insecure *bool) (IHaivisionClient, error) { // init haivision - haivisionClient := &Haivision{ + haivisionClient := &haivisionSdk{ Url: url, restClient: resty.New(), } @@ -57,7 +57,7 @@ func BuildHaivision(url string, debug bool, username string, password string, he return haivisionClient, nil } -func (o *Haivision) debugPrint(data interface{}) { +func (o *haivisionSdk) debugPrint(data interface{}) { if o.debug { log.Println(data) } diff --git a/haivision/haivision.go b/haivision/haivision.go index 42cad78..9d4d7fa 100644 --- a/haivision/haivision.go +++ b/haivision/haivision.go @@ -16,7 +16,7 @@ import ( udprtp "github.com/Allan-Nava/Haivision-go-sdk/haivision/udp_rtp" ) -type Haivision struct { +type haivisionSdk struct { Url string restClient *resty.Client DeviceID string @@ -57,7 +57,7 @@ type IHaivisionClient interface { // } -func (o *Haivision) HealthCheck() error { +func (o *haivisionSdk) HealthCheck() error { _, err := o.restyGet(o.Url, nil) if err != nil { return nil @@ -67,13 +67,13 @@ func (o *Haivision) HealthCheck() error { // -func (o *Haivision) IsDebug() bool { +func (o *haivisionSdk) IsDebug() bool { return o.debug } // Resty Methods -func (o *Haivision) restyPost(url string, body interface{}) (*resty.Response, error) { +func (o *haivisionSdk) restyPost(url string, body interface{}) (*resty.Response, error) { resp, err := o.restClient.R(). SetHeader("Accept", "application/json"). SetBody(body). @@ -91,7 +91,7 @@ func (o *Haivision) restyPost(url string, body interface{}) (*resty.Response, er } // get request -func (o *Haivision) restyGet(url string, queryParams map[string]string) (*resty.Response, error) { +func (o *haivisionSdk) restyGet(url string, queryParams map[string]string) (*resty.Response, error) { resp, err := o.restClient.R(). SetQueryParams(queryParams). Get(url) diff --git a/haivision/route.go b/haivision/route.go index b43f253..65feec3 100644 --- a/haivision/route.go +++ b/haivision/route.go @@ -52,7 +52,7 @@ func (o *Haivision) GetRoutesUdpRtp(deviceId string) (*route.ResponseRoutes[udpr return nil, nil }*/ -func (o *Haivision) GetRoutes(deviceId string) (*resty.Response, error) { +func (o *haivisionSdk) GetRoutes(deviceId string) (*resty.Response, error) { log.Println("GetRoutes ", deviceId) resp, err := o.restyGet(GET_LIST_OF_ROUTES(deviceId), nil) if err != nil { @@ -62,6 +62,15 @@ func (o *Haivision) GetRoutes(deviceId string) (*resty.Response, error) { return resp, nil } +func (o *haivisionSdk) GetRouteConfiguration(deviceId string, routeId string) (*resty.Response, error) { + log.Println("GetRouteConfiguration ", deviceId, routeId) + resp, err := o.restyGet(GET_ROUTE_CONFIGURATION(deviceId, routeId), nil) + if err != nil { + return nil, err + } + return resp, nil +} + /* Use this command to create an individual route. @@ -94,7 +103,7 @@ Response } */ -func (o *Haivision) CreateRouteSrt(deviceId string, rBody *route.RouteModel[srt.RequestSourceModelSRT, srt.RequestDestinationModelSrt]) (*route.ResponseCreateRoute, error) { +func (o *haivisionSdk) CreateRouteSrt(deviceId string, rBody *route.RouteModel[srt.RequestSourceModelSRT, srt.RequestDestinationModelSrt]) (*route.ResponseCreateRoute, error) { log.Println("CreateRouteSrt ", deviceId) if errs := validator.Validate(rBody); errs != nil { @@ -112,7 +121,7 @@ func (o *Haivision) CreateRouteSrt(deviceId string, rBody *route.RouteModel[srt. } return &obj, nil } -func (o *Haivision) CreateRouteRtmp(deviceId string, rBody *route.RouteModel[rtmp.RequestSourceModelRTMP, rtmp.RequestDestinationModelRtmp]) (*route.ResponseCreateRoute, error) { +func (o *haivisionSdk) CreateRouteRtmp(deviceId string, rBody *route.RouteModel[rtmp.RequestSourceModelRTMP, rtmp.RequestDestinationModelRtmp]) (*route.ResponseCreateRoute, error) { log.Println("CreateRouteRtmp ", deviceId) if errs := validator.Validate(rBody); errs != nil { // values not valid, deal with errors here @@ -129,7 +138,7 @@ func (o *Haivision) CreateRouteRtmp(deviceId string, rBody *route.RouteModel[rtm } return &obj, nil } -func (o *Haivision) CreateRouteRtsp(deviceId string, rBody *route.RouteModel[rtsp.RequestSourceModelRTSP, rtsp.RequestDestinationModelRtsp]) (*route.ResponseCreateRoute, error) { +func (o *haivisionSdk) CreateRouteRtsp(deviceId string, rBody *route.RouteModel[rtsp.RequestSourceModelRTSP, rtsp.RequestDestinationModelRtsp]) (*route.ResponseCreateRoute, error) { log.Println("CreateRouteRtsp ", deviceId) if errs := validator.Validate(rBody); errs != nil { // values not valid, deal with errors here @@ -147,7 +156,7 @@ func (o *Haivision) CreateRouteRtsp(deviceId string, rBody *route.RouteModel[rts return &obj, nil } -func (o *Haivision) CreateRouteUdpRtp(deviceId string, rBody *route.RouteModel[udprtp.RequestSourceModelUdpRtp, udprtp.RequestDestinationModelUdpRtp]) (*route.ResponseCreateRoute, error) { +func (o *haivisionSdk) CreateRouteUdpRtp(deviceId string, rBody *route.RouteModel[udprtp.RequestSourceModelUdpRtp, udprtp.RequestDestinationModelUdpRtp]) (*route.ResponseCreateRoute, error) { log.Println("CreateRouteUdpRtp ", deviceId) if errs := validator.Validate(rBody); errs != nil { // values not valid, deal with errors here @@ -165,7 +174,7 @@ func (o *Haivision) CreateRouteUdpRtp(deviceId string, rBody *route.RouteModel[u } // Start or Stop a route -func (o *Haivision) StartOrStopRoute(deviceId string, routeId string, command string) (*route.ResponseStartOrRoute, error) { +func (o *haivisionSdk) StartOrStopRoute(deviceId string, routeId string, command string) (*route.ResponseStartOrRoute, error) { log.Println("StartOrStopRoute ", deviceId, routeId, command) if command != route.START_ROUTE && command != route.STOP_ROUTE { return nil, errors.New("command must be start-route or stop-route") diff --git a/haivision/stats.go b/haivision/stats.go index f3b2db2..31d8b34 100644 --- a/haivision/stats.go +++ b/haivision/stats.go @@ -12,7 +12,7 @@ GET /api/gateway/[Device ID]/statistics?routeID=[Route ID] cookie: sessionID: [Session ID] */ -func (o *Haivision) GetRouteStatistics(deviceId string, routeId string) (*stats.ResponseRouteStatistics, error) { +func (o *haivisionSdk) GetRouteStatistics(deviceId string, routeId string) (*stats.ResponseRouteStatistics, error) { log.Println("GetStats ", deviceId, routeId) queryParams := map[string]string{ "routeID": routeId, @@ -34,7 +34,7 @@ GET /api/gateway/[Device ID]/statistics?routeID=[Route ID]&sourceID=[Source ID] cookie: sessionID: [Session ID] */ -func (o *Haivision) GetSourceStatistics(deviceId string, routeId string, sourceId string) (*stats.ResponseSourceStatistics, error) { +func (o *haivisionSdk) GetSourceStatistics(deviceId string, routeId string, sourceId string) (*stats.ResponseSourceStatistics, error) { log.Println("GetStats ", deviceId, routeId, sourceId) queryParams := map[string]string{ "routeID": routeId, @@ -65,7 +65,7 @@ cookie: sessionID: [Session ID] */ -func (o *Haivision) GetDestinationStatisticsById(deviceId string, routeId string, destinationID string) (*stats.ResponseDestinationStatistics, error) { +func (o *haivisionSdk) GetDestinationStatisticsById(deviceId string, routeId string, destinationID string) (*stats.ResponseDestinationStatistics, error) { log.Println("GetStats ", deviceId, routeId, destinationID) queryParams := map[string]string{ "routeID": routeId, @@ -82,7 +82,7 @@ func (o *Haivision) GetDestinationStatisticsById(deviceId string, routeId string return &obj, nil } -func (o *Haivision) GetDestinationStatisticsByName(deviceId string, routeId string, destinationName string) (*stats.ResponseDestinationStatistics, error) { +func (o *haivisionSdk) GetDestinationStatisticsByName(deviceId string, routeId string, destinationName string) (*stats.ResponseDestinationStatistics, error) { log.Println("GetStats ", deviceId, routeId, destinationName) queryParams := map[string]string{ "routeID": routeId, @@ -105,7 +105,7 @@ GET /api/gateway/[Device ID]/statistics/client?routeID=[Route ID]&destinationID= cookie: sessionID: [Session ID] */ -func (o *Haivision) GetSrtClientStatistics(deviceId string, routeId string, destinationID string, clientAddress string, clientPort string) (*stats.ResponseSrtClientStatistics, error) { +func (o *haivisionSdk) GetSrtClientStatistics(deviceId string, routeId string, destinationID string, clientAddress string, clientPort string) (*stats.ResponseSrtClientStatistics, error) { log.Println("GetStats ", deviceId, routeId, destinationID) queryParams := map[string]string{ "routeID": routeId,