Documentation ¶
Index ¶
- Constants
- func RawSearch(ctx context.Context, httpu HTTPUClientCtx, searchTarget string, numSends int) ([]*http.Response, error)
- func SSDPRawSearch(httpu HTTPUClient, searchTarget string, maxWaitSeconds int, numSends int) ([]*http.Response, error)
- func SSDPRawSearchCtx(ctx context.Context, httpu HTTPUClient, searchTarget string, ...) ([]*http.Response, error)
- type Entry
- type EventType
- type HTTPUClient
- type HTTPUClientCtx
- type Registry
- type Update
Constants ¶
const ( EventAlive = EventType(iota) EventUpdate EventByeBye )
const ( // SSDPAll is a value for searchTarget that searches for all devices and services. SSDPAll = "ssdp:all" // UPNPRootDevice is a value for searchTarget that searches for all root devices. UPNPRootDevice = "upnp:rootdevice" )
Variables ¶
This section is empty.
Functions ¶
func RawSearch ¶
func RawSearch( ctx context.Context, httpu HTTPUClientCtx, searchTarget string, numSends int, ) ([]*http.Response, error)
RawSearch performs a fairly raw SSDP search request, and returns the unique response(s) that it receives. Each response has the requested searchTarget, a USN, and a valid location. If the provided context times out or is canceled, the search will be aborted. numSends is the number of requests to send - 3 is a reasonable value for this.
The provided context should have a deadline, since the SSDP protocol requires the max wait time be included in search requests. If the context has no deadline, then a default deadline of 3 seconds will be applied.
func SSDPRawSearch ¶
func SSDPRawSearch(httpu HTTPUClient, searchTarget string, maxWaitSeconds int, numSends int) ([]*http.Response, error)
SSDPRawSearch is the legacy version of SSDPRawSearchCtx, but uses context.Background() as the context.
func SSDPRawSearchCtx ¶
func SSDPRawSearchCtx( ctx context.Context, httpu HTTPUClient, searchTarget string, maxWaitSeconds int, numSends int, ) ([]*http.Response, error)
SSDPRawSearchCtx performs a fairly raw SSDP search request, and returns the unique response(s) that it receives. Each response has the requested searchTarget, a USN, and a valid location. maxWaitSeconds states how long to wait for responses in seconds, and must be a minimum of 1 (the implementation waits an additional 100ms for responses to arrive), 2 is a reasonable value for this. numSends is the number of requests to send - 3 is a reasonable value for this.
Types ¶
type Entry ¶
type Entry struct { // The address that the entry data was actually received from. RemoteAddr string // Unique Service Name. Identifies a unique instance of a device or service. USN string // Notfication Type. The type of device or service being announced. NT string // Server's self-identifying string. Server string Host string // Location of the UPnP root device description. Location url.URL BootID int32 ConfigID int32 SearchPort uint16 // When the last update was received for this entry identified by this USN. LastUpdate time.Time // When the last update's cached values are advised to expire. CacheExpiry time.Time }
type HTTPUClient ¶
type HTTPUClient interface { Do( req *http.Request, timeout time.Duration, numSends int, ) ([]*http.Response, error) }
HTTPUClient is the interface required to perform HTTP-over-UDP requests.
type HTTPUClientCtx ¶
type HTTPUClientCtx interface { DoWithContext( req *http.Request, numSends int, ) ([]*http.Response, error) }
HTTPUClientCtx is an optional interface that will be used to perform HTTP-over-UDP requests if the client implements it.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry maintains knowledge of discovered devices and services.
NOTE: the interface for this is experimental and may change, or go away entirely.
func NewRegistry ¶
func NewRegistry() *Registry
func NewServerAndRegistry ¶
NewServerAndRegistry is a convenience function to create a registry, and an httpu server to pass it messages. Call ListenAndServe on the server for messages to be processed.
func (*Registry) AddListener ¶
func (*Registry) GetService ¶
GetService returns known service (or device) entries for the given service URN.
func (*Registry) RemoveListener ¶
func (*Registry) ServeMessage ¶
ServeMessage implements httpu.Handler, and uses SSDP NOTIFY requests to maintain the registry of devices and services.
type Update ¶
type Update struct { // The USN of the service. USN string // What happened. EventType EventType // The entry, which is nil if the service was not known and // EventType==EventByeBye. The contents of this must not be modified as it is // shared with the registry and other listeners. Once created, the Registry // does not modify the Entry value - any updates are replaced with a new // Entry value. Entry *Entry }