41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
package onvif
|
|
|
|
import (
|
|
"github.com/IOTechSystems/onvif"
|
|
)
|
|
|
|
type Connection struct {
|
|
Params DeviceParams `json:"params"`
|
|
Device *onvif.Device `json:"device"`
|
|
}
|
|
|
|
type DeviceParams struct {
|
|
Xaddr string `json:"xaddr"`
|
|
EndpointRefAddress string `json:"endpointRefAddress"`
|
|
Username string `json:"username"`
|
|
Password string `json:"password"`
|
|
AuthMode string `json:"authMode"`
|
|
}
|
|
|
|
func NewConnection(addr string, username string, password string) (*Connection, error) {
|
|
dev, err := onvif.NewDevice(onvif.DeviceParams{
|
|
Xaddr: addr,
|
|
Username: username,
|
|
Password: password,
|
|
})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &Connection{
|
|
Params: DeviceParams{
|
|
Xaddr: dev.GetDeviceParams().Xaddr,
|
|
EndpointRefAddress: dev.GetDeviceParams().EndpointRefAddress,
|
|
Username: dev.GetDeviceParams().Username,
|
|
Password: dev.GetDeviceParams().Password,
|
|
AuthMode: dev.GetDeviceParams().AuthMode,
|
|
},
|
|
Device: dev,
|
|
}, nil
|
|
}
|