SSDP client/consumer class. Source: lib/ssdp/consumer.rb
Make direct SSDP requests, listening for single or multiple responses.
Listen for SSDP notifications ('alive'/'byebye').
SSDP::Consumer.new(options = {})
If options
are provided, they can override global defaults (in SSDP::Defaults) for this instance (see individual calls for specific options).
consumer.search(options = {}, &block)
Perform an SSDP search request.
block
is only used for asynchronous requests.- Results will be directly returned for synchronous requests.
- Searching with
:first_only
will return a single hash, or nil. - Searching without
:first_only
will return an array of hashes. One entry for each response received during the timeout period. - Each result is a hash with format
{:status, :params, :body}
, where::status
=> HTTP Status/Command Line:params
=> hash of HTTP headers parsed into key-value pairs.:body
=> HTTP body of response, if present.
:service
- Service type string ('ST'/'NT' SSDP parameter) to search for.
- Should always be provided.
- If not provided, and
:no_warnings
is not set, call will display warning.
:synchronous
- If
true
, call will be blocking, and result will come through return value. - If
false
, call will be non-blocking, and result will be provided to the provided (block
) callback.
- If
:timeout
- Maximum time, in seconds, to wait for a search to complete.
- If
0
, ornil
, and:no_warnings
is not set, call will display warning.
:first_only
- If
true
, will only read the first response, returning a single object as soon as possible. - If
false
, will read all responses until timing out, returning an array of objects when complete.
- If
:no_warnings
- If set, inhibit any warnings this call may otherwise display.
:maxpack
- Maximum UDP packet size allowed to read (in bytes).
:filter
- A callable block to filter any results gathered.
bool filter({:status, :params, :body})
- If provided:
- If
:first_only
, the first result passing the filter will be returned. - Else, the set of all gathered results that pass the filter will be returned.
- If
consumer.start_watching_type(type, &block)
Register a service type ('ST'/'NT' SSDP parameter) to watch for, providing a callback block to be called each time a notification for the specified service type is encountered.
If the watcher thread is not running, adding a type to watch for will start it.
consumer.stop_watching_type(type)
Unregister a service type that was being watched for notifications.
If the watcher thread is running, removing the last watched type will stop it.
consumer.stop_watching_all
Convenience method to stop watching all previously registered service types.
Will stop the watcher thread, if it is currently running.