Sha256: 8cffa7c9eef79a69b90f7efcd5d7f8e364b64a8662d20aedc9595704702146ad

Contents?: true

Size: 1.64 KB

Versions: 53

Compression:

Stored size: 1.64 KB

Contents

require 'timeout'
require 'uri'

module Frank module Cucumber
class Bonjour

  FRANK_SERVICE_NAME = 'Frank UISpec server'
  FRANK_PORT = 37265
  LOOKUP_TIMEOUT = 10

  def debug string
    puts string if $DEBUG
  end

  def found_a_frank( reply )
    debug reply.inspect
    unless reply.flags.add?
      debug 'got a non-add reply'
      debug "flags: #{reply.flags.to_a.inspect}"
      return nil
    end

    resolve_service = DNSSD::Service.new
    addr_service = DNSSD::Service.new
    resolve_service.resolve reply do |r|
      debug "#{r.name} on #{r.target}:#{r.port}"

      address = nil
      addr_service.getaddrinfo r.target do |addrinfo|
        address = addrinfo.address
        break
      end

      debug "first address for #{r.target} is #{address}"
      return address
    end
  end

  def browse_for_franks_address
    require 'dnssd'

    DNSSD.browse! '_http._tcp.' do |reply|
      debug 'got a reply'
      if reply.name == FRANK_SERVICE_NAME 
        address = found_a_frank(reply)
        if address
          debug "OK WE HAVE AN ADDRESS: #{address}"
          return address
        end
      end
    end
  end

  def lookup_frank_base_uri
    puts "finding Frank server via Bonjour..."
    address = begin
      Timeout::timeout(LOOKUP_TIMEOUT){ address = browse_for_franks_address }
    rescue Timeout::Error
      puts "could not find Frank within #{LOOKUP_TIMEOUT} seconds"
    end

    if address
      puts "...found Frank via Bonjour: #{address}"
      return URI::HTTP.new( 'http', nil, address, FRANK_PORT, nil, nil, nil, nil, nil )
    else
      puts '...failed to find Frank server via Bonjour'
      return nil
    end
  end

end

end end

Version data entries

53 entries across 53 versions & 3 rubygems

Version Path
sc-frank-ios-1.2.3 lib/frank-cucumber/bonjour.rb
sc-frank-cucumber-1.2.1.bba52d7.debug lib/frank-cucumber/bonjour.rb
sc-frank-cucumber-1.2.1.e1e3ccb.debug lib/frank-cucumber/bonjour.rb
sc-frank-cucumber-1.2.1.1a856ca.debug lib/frank-cucumber/bonjour.rb
sc-frank-cucumber-1.2.1.b7791c5.debug lib/frank-cucumber/bonjour.rb
sc-frank-cucumber-1.2.1.3256dc1.debug lib/frank-cucumber/bonjour.rb
sc-frank-cucumber-1.2.1.9c95c03.debug lib/frank-cucumber/bonjour.rb
sc-frank-cucumber-1.2.1.1dcc760.debug lib/frank-cucumber/bonjour.rb
frank-cucumber-1.2.2 lib/frank-cucumber/bonjour.rb
sc-frank-cucumber-1.2.1.1dcc760 lib/frank-cucumber/bonjour.rb
frank-cucumber-1.2.1 lib/frank-cucumber/bonjour.rb
sc-frank-cucumber-1.2.1.902fa34 lib/frank-cucumber/bonjour.rb
sc-frank-cucumber-1.2.1.d2d00d2 lib/frank-cucumber/bonjour.rb
sc-frank-cucumber-1.2.1.c13cb90 lib/frank-cucumber/bonjour.rb
sc-frank-cucumber-1.2.1.00af28c lib/frank-cucumber/bonjour.rb
frank-cucumber-1.2.0 lib/frank-cucumber/bonjour.rb
frank-cucumber-1.2.0.pre1 lib/frank-cucumber/bonjour.rb
frank-cucumber-1.1.13.pre1 lib/frank-cucumber/bonjour.rb
frank-cucumber-1.1.12 lib/frank-cucumber/bonjour.rb
frank-cucumber-1.1.11.pre1 lib/frank-cucumber/bonjour.rb