Class: Airplay::Browser

Inherits:
Object
  • Object
show all
Defined in:
lib/airplay/browser.rb

Overview

Public: Browser class to find Airplay-enabled devices in the network

Constant Summary collapse

NoDevicesFound =
Class.new(StandardError)
SEARCH =
"_airplay._tcp."

Instance Method Summary collapse

Constructor Details

#initializeBrowser

Returns a new instance of Browser.



15
16
17
# File 'lib/airplay/browser.rb', line 15

def initialize
  @logger = Airplay::Logger.new("airplay::browser")
end

Instance Method Details

#browseObject

Public: Browses in the search of devices and adds them to the nodes

Returns nothing or raises NoDevicesFound if there are no devices



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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

#devicesObject

Public: Access to the node list

Returns the Devices list object



45
46
47
# File 'lib/airplay/browser.rb', line 45

def devices
  @_devices ||= Devices.new
end