google_anymote 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +1 -1
- data/bin/discover +64 -0
- data/lib/google_anymote/version.rb +1 -1
- metadata +4 -2
data/README.md
CHANGED
@@ -44,7 +44,7 @@ Use the `cert.pem` as your certificate when you pair with the Google TV.
|
|
44
44
|
|
45
45
|
This gem includes several command line utilities to get you up and running.
|
46
46
|
|
47
|
-
*
|
47
|
+
* discover - searches your network for compatible Google TVs
|
48
48
|
* pair - helps you pair your computer to a particular Google TV
|
49
49
|
|
50
50
|
### As a gem
|
data/bin/discover
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'socket'
|
3
|
+
require 'timeout'
|
4
|
+
require 'yaml'
|
5
|
+
YAML::ENGINE.yamler='syck'
|
6
|
+
|
7
|
+
ANYMOTE_PORT = 9101
|
8
|
+
LISTENER_PORT = 19800
|
9
|
+
COMMAND = "discover"
|
10
|
+
SERVICE = "_anymote._tcp"
|
11
|
+
|
12
|
+
# Create a new UDP listener
|
13
|
+
listener = UDPSocket::new( Socket::AF_INET )
|
14
|
+
listener::setsockopt( Socket::SOL_SOCKET, Socket::SO_BROADCAST, true )
|
15
|
+
listener.bind('', LISTENER_PORT)
|
16
|
+
|
17
|
+
# Create a UDP 'ping'
|
18
|
+
ping = UDPSocket::new( Socket::AF_INET )
|
19
|
+
ping::setsockopt( Socket::SOL_SOCKET, Socket::SO_BROADCAST, true )
|
20
|
+
|
21
|
+
# Use a background thread to send a 'ping' to everything on the network.
|
22
|
+
# We're using a specially constructe message so that only the GoogleTVs
|
23
|
+
# should respond.
|
24
|
+
t1 = Thread.new do
|
25
|
+
message = "#{COMMAND} #{SERVICE} #{LISTENER_PORT}"
|
26
|
+
loop do
|
27
|
+
ping.send(message, 0, "255.255.255.255", ANYMOTE_PORT)
|
28
|
+
sleep 1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
begin
|
33
|
+
devices = {}
|
34
|
+
devices['screens'] = {}
|
35
|
+
# Find as many devices as we can in n seconds
|
36
|
+
Timeout::timeout(4) {
|
37
|
+
puts "Looking for devices..."
|
38
|
+
loop do
|
39
|
+
# Wait for data to hit our socket...
|
40
|
+
data,from = listener.recvfrom(100)
|
41
|
+
|
42
|
+
# Parse the data and make sure that it's the correct message
|
43
|
+
reply = data.split
|
44
|
+
|
45
|
+
# If this is actually a response from a GoogleTV then store it for later
|
46
|
+
if SERVICE == reply[0]
|
47
|
+
host = reply[1]
|
48
|
+
port = reply[2]
|
49
|
+
uri = "http://www.example.com"
|
50
|
+
devices['screens'][reply[1]] = {'host' => host, 'port' => port, 'uri' => uri}
|
51
|
+
# puts " found device: #{devices['screens'][reply[1]]}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
}
|
55
|
+
rescue Timeout::Error => e
|
56
|
+
puts "---\nSearch complete. I found a total of #{devices['screens'].size} GoogleTV(s).\n"
|
57
|
+
puts devices.to_yaml.encoding
|
58
|
+
puts devices.to_yaml
|
59
|
+
puts devices.to_yaml.encoding
|
60
|
+
end
|
61
|
+
|
62
|
+
# Clean up
|
63
|
+
listener.close
|
64
|
+
ping.close
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_anymote
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: yard
|
@@ -63,6 +63,7 @@ description: Ruby implementation of the Google Anymote Protocol.
|
|
63
63
|
email:
|
64
64
|
- rnhurt@gmail.com
|
65
65
|
executables:
|
66
|
+
- discover
|
66
67
|
- pair
|
67
68
|
extensions: []
|
68
69
|
extra_rdoc_files: []
|
@@ -73,6 +74,7 @@ files:
|
|
73
74
|
- LICENSE
|
74
75
|
- README.md
|
75
76
|
- Rakefile
|
77
|
+
- bin/discover
|
76
78
|
- bin/pair
|
77
79
|
- google_anymote.gemspec
|
78
80
|
- lib/google_anymote.rb
|