Module: NLHue::SSDP
- Defined in:
- lib/nlhue/ssdp.rb
Defined Under Namespace
Classes: Response, SSDPConnection
Constant Summary collapse
- SSDP_ADDR =
'239.255.255.250'
- SSDP_PORT =
1900
Class Method Summary collapse
-
.discover(type = 'ssdp:all', timeout = 5, &block) ⇒ Object
Eventually calls the given block with a NLHue::SSDP::Response for each matching device found on the network within timeout seconds.
Class Method Details
.discover(type = 'ssdp:all', timeout = 5, &block) ⇒ Object
Eventually calls the given block with a NLHue::SSDP::Response for each matching device found on the network within timeout seconds. The block will be called with nil after the timeout. Returns the connection used for discovery; call #shutdown on the returned object to abort discovery.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/nlhue/ssdp.rb', line 20 def self.discover type='ssdp:all', timeout=5, &block raise 'A block must be given to discover().' unless block_given? con = EM::open_datagram_socket('0.0.0.0', 0, SSDPConnection, type, timeout, block) EM.add_timer(timeout) do con.close_connection EM.next_tick do yield nil end end # TODO: Structure this using EM::Deferrable instead? con end |