Module: Huey::SSDP
- Defined in:
- lib/huey/ssdp.rb,
lib/huey/ssdp/searcher.rb
Defined Under Namespace
Classes: Searcher
Class Method Summary collapse
Class Method Details
.hue_ip ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/huey/ssdp.rb', line 11 def self.hue_ip return @hue_ip if @hue_ip multicast_searcher = proc do EM.open_datagram_socket('0.0.0.0', 0, Huey::SSDP::Searcher) end response = nil EM.run do ms = multicast_searcher.call ms.discovery_responses.subscribe do |notification| response = notification EM.stop end EM.add_timer(Huey::Config.ssdp_ttl) { EM.stop } trap('INT') { EM.stop } trap('TERM') { EM.stop } trap('HUP') { EM.stop } end raise Huey::Errors::CouldNotFindHue, 'No IP address found for the Hue hub' unless response @hue_ip = response[:location].match(/http:\/\/(.*?):(.*?)\//)[1] end |