Class: GoogleAnymote::Pair

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

Overview

Class to send events to a connected GoogleTV

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cert, host, client_name = '', service_name = 'AnyMote') ⇒ Object

Initializes the Pair class

Parameters:

  • cert (Object)

    SSL certificate for this client

  • host (String)

    hostname or IP address of the Google TV

  • client_name (String) (defaults to: '')

    name of the client your connecting from

  • service_name (String) (defaults to: 'AnyMote')

    name of the service (generally ‘AnyMote’)



21
22
23
24
25
26
27
# File 'lib/google_anymote/pair.rb', line 21

def initialize(cert, host, client_name = '', service_name = 'AnyMote')
  @pair = PairingRequest.new
  @cert = cert
  @host = host
  @pair.client_name  = client_name
  @pair.service_name = service_name
end

Instance Attribute Details

#certObject (readonly)

Returns the value of attribute cert.



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

def cert
  @cert
end

#gtvObject (readonly)

Returns the value of attribute gtv.



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

def gtv
  @gtv
end

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#pairObject (readonly)

Returns the value of attribute pair.



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

def pair
  @pair
end

Instance Method Details

#complete_pairing(code) ⇒ Object

Complete the pairing process

Parameters:

  • code (String)

    The code displayed on the Google TV we are trying to pair with.

Raises:



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/google_anymote/pair.rb', line 67

def complete_pairing(code)
  # Send secret code to the TV to compete the pairing process
  secret = Secret.new
  secret.secret = encode_hex_secret(code)
  outer = send_message(secret, OuterMessage::MessageType::MESSAGE_TYPE_SECRET)

  # Clean up
  @gtv.ssl_client.close

  raise PairingFailed, outer.status unless OuterMessage::Status::STATUS_OK == outer.status
end

#start_pairingObject

Start the pairing process

Once the TV recieves the pairing request it will display a 4 digit number. This number needs to be feed into the next step in the process, complete_pairing().

Raises:



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/google_anymote/pair.rb', line 36

def start_pairing
  @gtv = GoogleAnymote::TV.new(@cert, host, 9551 + 1)

  # Let the TV know that we want to pair with it
  send_message(pair, OuterMessage::MessageType::MESSAGE_TYPE_PAIRING_REQUEST)

  # Build the options and send them to the TV
  options       = Options.new
  encoding      = Options::Encoding.new
  encoding.type = Options::Encoding::EncodingType::ENCODING_TYPE_HEXADECIMAL
  encoding.symbol_length = 4
  options.input_encodings   << encoding
  options.output_encodings  << encoding
  send_message(options, OuterMessage::MessageType::MESSAGE_TYPE_OPTIONS)

  # Build configuration and send it to the TV
  config        = Configuration.new
  encoding      = Options::Encoding.new
  encoding.type = Options::Encoding::EncodingType::ENCODING_TYPE_HEXADECIMAL
  config.encoding               = encoding
  config.encoding.symbol_length = 4
  config.client_role            = Options::RoleType::ROLE_TYPE_INPUT
  outer = send_message(config, OuterMessage::MessageType::MESSAGE_TYPE_CONFIGURATION)
  
  raise PairingFailed, outer.status unless OuterMessage::Status::STATUS_OK == outer.status
end