Class: Frisky::SSDP::Listener
- Inherits:
-
MulticastConnection
- Object
- EventMachine::Connection
- MulticastConnection
- Frisky::SSDP::Listener
- Includes:
- LogSwitch
- Defined in:
- lib/frisky/ssdp/listener.rb
Constant Summary
Constants included from NetworkConstants
NetworkConstants::BROADCAST_IP, NetworkConstants::MULTICAST_IP, NetworkConstants::MULTICAST_PORT, NetworkConstants::TTL
Instance Attribute Summary collapse
-
#alive_notifications ⇒ EventMachine::Channel
readonly
Provides subscribers with notifications from devices that have come online (sent
ssdp:alive
notifications). -
#byebye_notifications ⇒ EventMachine::Channel
readonly
Provides subscribers with notifications from devices that have gone offline (sent
ssd:byebye
notifications).
Instance Method Summary collapse
-
#receive_data(response) ⇒ Object
This is the callback called by EventMachine when it receives data on the socket that’s been opened for this connection.
Methods inherited from MulticastConnection
#initialize, #parse, #peer_info, #set_membership, #set_multicast_ttl, #set_ttl, #setup_multicast_socket, #switch_multicast_loop
Constructor Details
This class inherits a constructor from Frisky::SSDP::MulticastConnection
Instance Attribute Details
#alive_notifications ⇒ EventMachine::Channel (readonly)
Returns Provides subscribers with notifications from devices that have come online (sent ssdp:alive
notifications).
9 10 11 |
# File 'lib/frisky/ssdp/listener.rb', line 9 def alive_notifications @alive_notifications end |
#byebye_notifications ⇒ EventMachine::Channel (readonly)
Returns Provides subscribers with notifications from devices that have gone offline (sent ssd:byebye
notifications).
13 14 15 |
# File 'lib/frisky/ssdp/listener.rb', line 13 def byebye_notifications @byebye_notifications end |
Instance Method Details
#receive_data(response) ⇒ Object
This is the callback called by EventMachine when it receives data on the socket that’s been opened for this connection. In this case, the method parses the SSDP notifications into Hashes and adds them to the appropriate EventMachine::Channel (provided as accessor methods). This effectively means that in each Channel, you get a Hash that represents the headers for each notification that comes in on the socket.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/frisky/ssdp/listener.rb', line 23 def receive_data(response) ip, port = peer_info log "Response from #{ip}:#{port}:\n#{response}\n" parsed_response = parse(response) return unless parsed_response.has_key? :nts if parsed_response[:nts] == 'ssdp:alive' @alive_notifications << parsed_response elsif parsed_response[:nts] == 'ssdp:byebye' @byebye_notifications << parsed_response else raise "Unknown NTS value: #{parsed_response[:nts]}" end end |