Class: Huey::SSDP::Searcher
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- Huey::SSDP::Searcher
- Defined in:
- lib/huey/ssdp/searcher.rb
Instance Attribute Summary collapse
-
#discovery_responses ⇒ Object
readonly
Returns the value of attribute discovery_responses.
Instance Method Summary collapse
-
#initialize ⇒ Searcher
constructor
A new instance of Searcher.
- #m_search ⇒ Object
- #parse(data) ⇒ Object
- #post_init ⇒ Object
- #receive_data(response) ⇒ Object
Constructor Details
#initialize ⇒ Searcher
Returns a new instance of Searcher.
14 15 16 |
# File 'lib/huey/ssdp/searcher.rb', line 14 def initialize @discovery_responses = EM::Channel.new end |
Instance Attribute Details
#discovery_responses ⇒ Object (readonly)
Returns the value of attribute discovery_responses.
12 13 14 |
# File 'lib/huey/ssdp/searcher.rb', line 12 def discovery_responses @discovery_responses end |
Instance Method Details
#m_search ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/huey/ssdp/searcher.rb', line 48 def m_search "M-SEARCH * HTTP/1.1\\r\nHOST: \#{Huey::Config.ssdp_ip}:\#{Huey::Config.ssdp_port}\\r\nMAN: \"ssdp:discover\"\\r\nMX: \#{Huey::Config.ssdp_ttl}\\r\nST: urn:schemas-upnp-org:device:Basic:1\\r\n\\r\n" end |
#parse(data) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/huey/ssdp/searcher.rb', line 24 def parse(data) new_data = {} data.each_line do |line| if match = line.match(/(\S+):(.*)/) key = match[1].gsub('-', '_').downcase.to_sym value = match[2] new_data[key] = value.strip end end new_data end |
#post_init ⇒ Object
18 19 20 21 22 |
# File 'lib/huey/ssdp/searcher.rb', line 18 def post_init if send_datagram(m_search, Huey::Config.ssdp_ip, Huey::Config.ssdp_port) > 0 Huey.logger.debug "Sent datagram search:\n#{m_search}" end end |
#receive_data(response) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/huey/ssdp/searcher.rb', line 38 def receive_data(response) parsed_response = parse(response) Huey.logger.debug "Received response: #{parsed_response}" return if parsed_response.has_key? :nts return if parsed_response[:man] && parsed_response[:man] =~ /ssdp:discover/ @discovery_responses << parsed_response end |