Class: RUPNP::SSDP::Listener
- Inherits:
-
MulticastConnection
- Object
- EM::Connection
- MulticastConnection
- RUPNP::SSDP::Listener
- Includes:
- HTTP
- Defined in:
- lib/rupnp/ssdp/listener.rb
Overview
Listener class for listening for devices’ notifications
Constant Summary
Constants included from LogMixin
Instance Attribute Summary collapse
-
#notifications ⇒ EM::Channel
readonly
Channel to receive notifications.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Listener
constructor
A new instance of Listener.
- #receive_data(data) ⇒ Object
Methods included from HTTP
#get_http_headers, #get_http_verb, #is_http_status_ok?
Methods inherited from MulticastConnection
Methods included from LogMixin
Constructor Details
#initialize(options = {}) ⇒ Listener
Returns a new instance of Listener.
14 15 16 17 18 |
# File 'lib/rupnp/ssdp/listener.rb', line 14 def initialize(={}) @notifications = EM::Channel.new super [:ttl] end |
Instance Attribute Details
#notifications ⇒ EM::Channel (readonly)
Channel to receive notifications
10 11 12 |
# File 'lib/rupnp/ssdp/listener.rb', line 10 def notifications @notifications end |
Instance Method Details
#receive_data(data) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rupnp/ssdp/listener.rb', line 21 def receive_data(data) port, ip = peer_info log :info, "Receive notification from #{ip}:#{port}" log :debug, data io = StringIO.new(data) h = get_http_verb(io) if h.nil? log :warn, "No HTTP command" return elsif h[:verb] == 'M-SEARCH' return elsif !(h[:verb].upcase == 'NOTIFY' and h[:path] == '*' and h[:http_version] == '1.1') log :warn, "Unknown HTTP command: #{h[:cmd]}" return end @notifications << get_http_headers(io) end |