class Airplay::Browser
Public: Browser
class to find Airplay-enabled devices in the network
Constants
- NoDevicesFound
- SEARCH
Public Class Methods
# File lib/airplay/browser.rb, line 15 def initialize @logger = Airplay::Logger.new("airplay::browser") end
Public Instance Methods
Public: Browses in the search of devices and adds them to the nodes
Returns nothing or raises NoDevicesFound
if there are no devices
# File lib/airplay/browser.rb, line 23 def browse timeout(5) do nodes = [] DNSSD.browse!(SEARCH) do |node| nodes << node next if node.flags.more_coming? nodes.each do |node| resolve(node) end break end end rescue Timeout::Error => e raise NoDevicesFound end
Public: Access to the node list
Returns the Devices
list object
# File lib/airplay/browser.rb, line 45 def devices @_devices ||= Devices.new end
Private Instance Methods
Private: Creates a device
name - The device name address - The device address
Returns nothing
# File lib/airplay/browser.rb, line 116 def create_device(name, address, type) Device.new( name: name.gsub(/\u00a0/, ' '), address: address, type: type ) end
Private: Resolves the node complete address
resolved - The DNS Resolved object
Returns a string with the address (host:ip)
# File lib/airplay/browser.rb, line 91 def get_device_address(resolved) host = get_device_host(resolved.target) "#{host}:#{resolved.port}" end
Private: Resolves the node ip or hostname
resolved - The DNS Resolved object
Returns a string with the ip or the hostname
# File lib/airplay/browser.rb, line 102 def get_device_host(target) info = Socket.getaddrinfo(target, nil, Socket::AF_INET) info[0][2] rescue SocketError target end
Private: Gets the device type
records - The text records hash to be investigated
Returns a symbol with the type
# File lib/airplay/browser.rb, line 76 def get_type(records) # rhd means Remote HD the first product of the Airserver people if records.has_key?("rhd") :airserver else :apple_tv end end
Private: Resolves a node given a node and a resolver
node - The given node resolver - The DNSSD::Server that is resolving nodes
Returns if there are more nodes coming
# File lib/airplay/browser.rb, line 58 def node_resolver(node, resolved) address = get_device_address(resolved) type = get_type(resolved.text_record) device = create_device(node.name, address, type) device.text_records = resolved.text_record devices << device resolved.flags.more_coming? end
Private: Resolves the node information given a node
node - The node from the DNSSD browsing
Returns nothing
# File lib/airplay/browser.rb, line 130 def resolve(node) DNSSD.resolve(node) do |resolved| break unless node_resolver(node, resolved) end end