Class: NetServiceBrowser

Inherits:
Object
  • Object
show all
Defined in:
lib/motion-net-service/net_service_browser.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(search_type, options = {}) ⇒ NetServiceBrowser

Returns a new instance of NetServiceBrowser.



2
3
4
5
6
7
8
9
10
11
# File 'lib/motion-net-service/net_service_browser.rb', line 2

def initialize(search_type, options={})
  default_options = {
    search_type: search_type,
    domain: ""
  }
  @options = options.merge(default_options)

  @net_service_browser = NSNetServiceBrowser.alloc.init
  @net_service_browser.setDelegate(self)
end

Class Method Details

.search(search_type, options = {}, &block) ⇒ Object



23
24
25
26
27
# File 'lib/motion-net-service/net_service_browser.rb', line 23

def self.search(search_type, options={}, &block)
  NetServiceBrowser.new(search_type, options).tap do |browser|
    browser.search(&block)
  end
end

Instance Method Details

#netServiceBrowser(netServiceBrowser, didNotSearch: errorInfo) ⇒ Object



40
41
42
# File 'lib/motion-net-service/net_service_browser.rb', line 40

def netServiceBrowser(netServiceBrowser, didFindService: service, moreComing: moreComing)
  @on_did_find_service.call(NetService.from_ns_net_service(service), moreComing) if @on_did_find_service
end

#search(&block) ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/motion-net-service/net_service_browser.rb', line 29

def search(&block)
  if block
    on_did_find_service do |service, more_coming|
      service.resolve do
        block.call(service, more_coming)
      end
    end
  end
  @net_service_browser.searchForServicesOfType @options[:search_type], inDomain: @options[:domain]
end