gonvif

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 15 Imported by: 0

README

gonvif

ONVIF client library for Go — discover and control IP cameras via the ONVIF protocol.

Installation

go get github.com/sonnt85/gonvif

Features

  • WS-Discovery to find ONVIF devices on a network interface
  • Connect to ONVIF devices by address with optional HTTP client
  • Automatic capability discovery (Media, PTZ, Imaging, Events, Analytics)
  • WS-Security (UsernameToken) authentication
  • Call arbitrary ONVIF SOAP methods via CallMethod
  • Structured types for Device, Media, PTZ, Imaging, Event, and Analytics services
  • ISO 8601 duration support

Usage

// Discover NVT devices on an interface
devices := gonvif.GetAvailableDevicesAtSpecificEthernetInterface("eth0")

// Connect to a known camera
dev, err := gonvif.NewDevice(gonvif.DeviceParams{
    Xaddr:    "192.168.1.100",
    Username: "admin",
    Password: "secret",
})
if err != nil {
    log.Fatal(err)
}

// List discovered service endpoints
fmt.Println(dev.GetServices())

// Call a ONVIF method (e.g., GetProfiles from media package)
resp, err := dev.CallMethod(media.GetProfiles{})

API

Types
  • Device — represents an ONVIF device; holds endpoints and device info
  • DeviceParams — connection parameters (address, credentials, HTTP client)
  • DeviceType — NVD / NVS / NVA / NVT constants
  • DeviceInfo — device information returned by GetDeviceInformation
Functions
  • NewDevice(params DeviceParams) (*Device, error) — connect to a device and discover its capabilities
  • GetAvailableDevicesAtSpecificEthernetInterface(iface string) []Device — WS-Discovery probe on a network interface
Device Methods
  • CallMethod(method interface{}) (*http.Response, error) — call any ONVIF SOAP method
  • GetServices() map[string]string — return discovered service endpoint URLs
  • GetDeviceInfo() DeviceInfo — return device information
  • GetEndpoint(name string) string — return endpoint URL for a named service
Sub-packages
  • device — Device service types and operations
  • media — Media service types
  • ptz — PTZ service types
  • event — Event service types (Subscribe, PullMessages, etc.)
  • Imaging — Imaging service types
  • analytics — Analytics service types
  • wsdiscovery — WS-Discovery probe implementation
  • gosoap — SOAP message builder with WS-Security support
  • onvifutils — ONVIF utility helpers
  • xsd — XSD built-in and ONVIF schema types

Author

sonnt85thanhson.rf@gmail.com

License

MIT License - see LICENSE for details.

Documentation

Overview

Package onvif is developed to provide an ONVIF client implementation on Go programming language

Index

Constants

This section is empty.

Variables

View Source
var Xlmns = map[string]string{
	"onvif":   "http://www.onvif.org/ver10/schema",
	"tds":     "http://www.onvif.org/ver10/device/wsdl",
	"trt":     "http://www.onvif.org/ver10/media/wsdl",
	"tev":     "http://www.onvif.org/ver10/events/wsdl",
	"tptz":    "http://www.onvif.org/ver20/ptz/wsdl",
	"timg":    "http://www.onvif.org/ver20/imaging/wsdl",
	"tan":     "http://www.onvif.org/ver20/analytics/wsdl",
	"xmime":   "http://www.w3.org/2005/05/xmlmime",
	"wsnt":    "http://docs.oasis-open.org/wsn/b-2",
	"xop":     "http://www.w3.org/2004/08/xop/include",
	"wsa":     "http://www.w3.org/2005/08/addressing",
	"wstop":   "http://docs.oasis-open.org/wsn/t-1",
	"wsntw":   "http://docs.oasis-open.org/wsn/bw-2",
	"wsrf-rw": "http://docs.oasis-open.org/wsrf/rw-2",
	"wsaw":    "http://www.w3.org/2006/05/addressing/wsdl",
}

Xlmns XML Scheam

Functions

This section is empty.

Types

type Device

type Device struct {
	DeviceInfo
	// contains filtered or unexported fields
}

Device for a new device of onvif and deviceInfo struct represents an abstract ONVIF device. It contains methods, which helps to communicate with ONVIF device

func GetAvailableDevicesAtSpecificEthernetInterface

func GetAvailableDevicesAtSpecificEthernetInterface(interfaceName string) []Device

GetAvailableDevicesAtSpecificEthernetInterface ...

func NewDevice

func NewDevice(params DeviceParams) (*Device, error)

NewDevice function construct a ONVIF Device entity

func (Device) CallMethod

func (dev Device) CallMethod(method interface{}) (*http.Response, error)

CallMethod functions call an method, defined <method> struct. You should use Authenticate method to call authorized requests.

func (*Device) GetDeviceInfo

func (dev *Device) GetDeviceInfo() DeviceInfo

GetDeviceInfo return available endpoints

func (*Device) GetEndpoint

func (dev *Device) GetEndpoint(name string) string

GetEndpoint returns specific ONVIF service endpoint address

func (*Device) GetServices

func (dev *Device) GetServices() map[string]string

GetServices return available endpoints

type DeviceParams

type DeviceParams struct {
	Xaddr      string
	Username   string
	Password   string
	HttpClient *http.Client
}

type DeviceType

type DeviceType int

DeviceType alias for int

const (
	NVD DeviceType = iota
	NVS
	NVA
	NVT
)

Onvif Device Tyoe

func (DeviceType) String

func (devType DeviceType) String() string

Directories

Path Synopsis
xsd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL