-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds doctor command and improve listing
- Loading branch information
Showing
5 changed files
with
105 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
module Airplay | ||
module CLI | ||
class Doctor | ||
DebugDevice = Struct.new(:node, :resolved) do | ||
def host | ||
info = Socket.getaddrinfo(resolved.target, nil, Socket::AF_INET) | ||
info[0][2] | ||
rescue SocketError | ||
target | ||
end | ||
end | ||
|
||
attr_accessor :devices | ||
|
||
def initialize | ||
@devices = [] | ||
end | ||
|
||
def information | ||
find_devices! | ||
|
||
devices.each do |device| | ||
puts <<-EOS.gsub!(" "*12, "") | ||
Name: #{device.node.name} | ||
Host: #{device.host} | ||
Port: #{device.resolved.port} | ||
Full Name: #{device.node.fullname} | ||
Iface: #{device.node.interface_name} | ||
TXT: #{device.resolved.text_record} | ||
EOS | ||
end | ||
end | ||
|
||
private | ||
|
||
def find_devices! | ||
timeout(5) do | ||
DNSSD.browse!(Airplay::Browser::SEARCH) do |node| | ||
try_resolving(node) | ||
break unless node.flags.more_coming? | ||
end | ||
end | ||
end | ||
|
||
def try_resolving(node) | ||
timeout(5) do | ||
resolver = DNSSD::Service.new | ||
resolver.resolve(node) do |resolved| | ||
devices << DebugDevice.new(node, resolved) | ||
|
||
break unless resolved.flags.more_coming? | ||
end | ||
end | ||
end | ||
|
||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters