Documentation ¶
Overview ¶
goupnp is an implementation of a client for various UPnP services.
For most uses, it is recommended to use the code-generated packages under github.com/huin/goupnp/dcps. Example use is shown at http://godoc.org/github.com/huin/goupnp/example
A commonly used client is internetgateway1.WANPPPConnection1: http://godoc.org/github.com/huin/goupnp/dcps/internetgateway1#WANPPPConnection1
Currently only a couple of schemas have code generated for them from the UPnP example XML specifications. Not all methods will work on these clients, because the generated stubs contain the full set of specified methods from the XML specifications, and the discovered services will likely support a subset of those methods.
Index ¶
- Constants
- type ContextError
- type Device
- type Icon
- type MaybeRootDevice
- type RootDevice
- type Service
- type ServiceClient
- func NewServiceClients(searchTarget string) (clients []ServiceClient, errors []error, err error)
- func NewServiceClientsByURL(loc *url.URL, searchTarget string) ([]ServiceClient, error)
- func NewServiceClientsCtx(ctx context.Context, searchTarget string) (clients []ServiceClient, errors []error, err error)
- func NewServiceClientsFromRootDevice(rootDevice *RootDevice, loc *url.URL, searchTarget string) ([]ServiceClient, error)
- type SpecVersion
- type URLField
Constants ¶
const (
DeviceXMLNamespace = "urn:schemas-upnp-org:device-1-0"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ContextError ¶
ContextError is an error that wraps an error with some context information.
func (ContextError) Error ¶
func (err ContextError) Error() string
type Device ¶
type Device struct { DeviceType string `xml:"deviceType"` FriendlyName string `xml:"friendlyName"` Manufacturer string `xml:"manufacturer"` ManufacturerURL URLField `xml:"manufacturerURL"` ModelDescription string `xml:"modelDescription"` ModelName string `xml:"modelName"` ModelNumber string `xml:"modelNumber"` ModelURL URLField `xml:"modelURL"` SerialNumber string `xml:"serialNumber"` UDN string `xml:"UDN"` UPC string `xml:"UPC,omitempty"` Icons []Icon `xml:"iconList>icon,omitempty"` Services []Service `xml:"serviceList>service,omitempty"` Devices []Device `xml:"deviceList>device,omitempty"` // Extra observed elements: PresentationURL URLField `xml:"presentationURL"` }
Device is a UPnP device. It can have child devices.
func (*Device) FindService ¶
FindService finds all (if any) Services under the device and its descendents that have the given ServiceType.
func (*Device) SetURLBase ¶
SetURLBase sets the URLBase for the Device and its underlying components.
func (*Device) VisitDevices ¶
VisitDevices calls visitor for the device, and all its descendent devices.
func (*Device) VisitServices ¶
VisitServices calls visitor for all Services under the device and all its descendent devices.
type Icon ¶
type Icon struct { Mimetype string `xml:"mimetype"` Width int32 `xml:"width"` Height int32 `xml:"height"` Depth int32 `xml:"depth"` URL URLField `xml:"url"` }
Icon is a representative image that a device might include in its description.
func (*Icon) SetURLBase ¶
SetURLBase sets the URLBase for the Icon.
type MaybeRootDevice ¶
type MaybeRootDevice struct { // Set iff Err == nil. Root *RootDevice // The location the device was discovered at. This can be used with // DeviceByURL, assuming the device is still present. A location represents // the discovery of a device, regardless of if there was an error probing it. Location *url.URL // Any error encountered probing a discovered device. Err error }
MaybeRootDevice contains either a RootDevice or an error.
func DiscoverDevices ¶
func DiscoverDevices(searchTarget string) ([]MaybeRootDevice, error)
DiscoverDevices is deprecated. Use DiscoverDevicesCtx instead.
func DiscoverDevicesCtx ¶
func DiscoverDevicesCtx(ctx context.Context, searchTarget string) ([]MaybeRootDevice, error)
DiscoverDevicesCtx attempts to find targets of the given type. This is typically the entry-point for this package. searchTarget is typically a URN in the form "urn:schemas-upnp-org:device:..." or "urn:schemas-upnp-org:service:...". A single error is returned for errors while attempting to send the query. An error or RootDevice is returned for each discovered RootDevice.
type RootDevice ¶
type RootDevice struct { XMLName xml.Name `xml:"root"` SpecVersion SpecVersion `xml:"specVersion"` URLBase url.URL `xml:"-"` URLBaseStr string `xml:"URLBase"` Device Device `xml:"device"` }
RootDevice is the device description as described by section 2.3 "Device description" in http://upnp.org/specs/arch/UPnP-arch-DeviceArchitecture-v1.1.pdf
func DeviceByURL ¶
func DeviceByURL(loc *url.URL) (*RootDevice, error)
func (*RootDevice) SetURLBase ¶
func (root *RootDevice) SetURLBase(urlBase *url.URL)
SetURLBase sets the URLBase for the RootDevice and its underlying components.
type Service ¶
type Service struct { ServiceType string `xml:"serviceType"` ServiceId string `xml:"serviceId"` SCPDURL URLField `xml:"SCPDURL"` ControlURL URLField `xml:"controlURL"` EventSubURL URLField `xml:"eventSubURL"` }
Service is a service provided by a UPnP Device.
func (*Service) NewSOAPClient ¶
func (srv *Service) NewSOAPClient() *soap.SOAPClient
func (*Service) RequestSCDP ¶
RequestSCDP requests the SCPD (soap actions and state variables description) for the service.
func (*Service) SetURLBase ¶
SetURLBase sets the URLBase for the Service.
type ServiceClient ¶
type ServiceClient struct { SOAPClient *soap.SOAPClient RootDevice *RootDevice Location *url.URL Service *Service }
ServiceClient is a SOAP client, root device and the service for the SOAP client rolled into one value. The root device, location, and service are intended to be informational. Location can be used to later recreate a ServiceClient with NewServiceClientByURL if the service is still present; bypassing the discovery process.
func NewServiceClients ¶
func NewServiceClients(searchTarget string) (clients []ServiceClient, errors []error, err error)
NewServiceClients is deprecated. Use NewServiceClientsCtx instead.
func NewServiceClientsByURL ¶
func NewServiceClientsByURL(loc *url.URL, searchTarget string) ([]ServiceClient, error)
NewServiceClientsByURL creates client(s) for the given service URN, for a root device at the given URL.
func NewServiceClientsCtx ¶
func NewServiceClientsCtx(ctx context.Context, searchTarget string) (clients []ServiceClient, errors []error, err error)
NewServiceClientsCtx discovers services, and returns clients for them. err will report any error with the discovery process (blocking any device/service discovery), errors reports errors on a per-root-device basis.
func NewServiceClientsFromRootDevice ¶
func NewServiceClientsFromRootDevice(rootDevice *RootDevice, loc *url.URL, searchTarget string) ([]ServiceClient, error)
NewServiceClientsFromDevice creates client(s) for the given service URN, in a given root device. The loc parameter is simply assigned to the Location attribute of the returned ServiceClient(s).
func (*ServiceClient) GetServiceClient ¶
func (client *ServiceClient) GetServiceClient() *ServiceClient
GetServiceClient returns the ServiceClient itself. This is provided so that the service client attributes can be accessed via an interface method on a wrapping type.
type SpecVersion ¶
SpecVersion is part of a RootDevice, describes the version of the specification that the data adheres to.