Class: GoogleAnymote::TV

Inherits:
Object
  • Object
show all
Defined in:
lib/google_anymote/tv.rb

Overview

Class to send events to a connected GoogleTV

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cert, host, port = 9551) ⇒ Object

Initializes the TV class.

Parameters:

  • cert (Object)

    SSL certificate for this client

  • host (String)

    hostname or IP address of the Google TV

  • port (Number) (defaults to: 9551)

    port number of the Google TV



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/google_anymote/tv.rb', line 20

def initialize(cert, host, port = 9551)
  @host = host
  @port = port
  @cert = cert
  @remote  = RemoteMessage.new
  @request = RequestMessage.new
  @fling   = Fling.new

  # Build the SSL stuff
  @context       = OpenSSL::SSL::SSLContext.new
  @context.key   = OpenSSL::PKey::RSA.new @cert
  @context.cert  = OpenSSL::X509::Certificate.new @cert

  connect_to_unit
end

Instance Attribute Details

#certObject (readonly)

Returns the value of attribute cert.



11
12
13
# File 'lib/google_anymote/tv.rb', line 11

def cert
  @cert
end

#cotextObject (readonly)

Returns the value of attribute cotext.



11
12
13
# File 'lib/google_anymote/tv.rb', line 11

def cotext
  @cotext
end

#flingObject (readonly)

Returns the value of attribute fling.



11
12
13
# File 'lib/google_anymote/tv.rb', line 11

def fling
  @fling
end

#hostObject (readonly)

Returns the value of attribute host.



11
12
13
# File 'lib/google_anymote/tv.rb', line 11

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



11
12
13
# File 'lib/google_anymote/tv.rb', line 11

def port
  @port
end

#remoteObject (readonly)

Returns the value of attribute remote.



11
12
13
# File 'lib/google_anymote/tv.rb', line 11

def remote
  @remote
end

#requestObject (readonly)

Returns the value of attribute request.



11
12
13
# File 'lib/google_anymote/tv.rb', line 11

def request
  @request
end

#ssl_clientObject (readonly)

Returns the value of attribute ssl_client.



11
12
13
# File 'lib/google_anymote/tv.rb', line 11

def ssl_client
  @ssl_client
end

Instance Method Details

#connect_to_unitObject

Connect this object to a Google TV



38
39
40
41
42
43
44
45
46
47
# File 'lib/google_anymote/tv.rb', line 38

def connect_to_unit
  puts "Connecting to '#{@host}..."
  begin
    tcp_client  = TCPSocket.new @host, @port
    @ssl_client = OpenSSL::SSL::SSLSocket.new tcp_client, @context
    @ssl_client.connect
  rescue Exception => e
    puts "Could not connect to '#{@host}: #{e}"
  end
end

#finalizeObject

Clean up any sockets or other garbage.



51
52
53
# File 'lib/google_anymote/tv.rb', line 51

def finalize()
  @ssl_client.close
end

#fling_uri(uri) ⇒ Object

Fling a URI to the Google TV connected to this object



57
58
59
60
61
62
# File 'lib/google_anymote/tv.rb', line 57

def fling_uri(uri)
  @fling.uri = uri
  @request.fling_message = fling
  @remote.request_message = @request
  send_message(@remote)
end