Class: Ably::Realtime::Connection

Inherits:
EventMachine::Connection
  • Object
show all
Includes:
Modules::Conversions, Callbacks
Defined in:
lib/ably/realtime/connection.rb

Instance Method Summary collapse

Methods included from Callbacks

#on, #trigger

Constructor Details

#initialize(client) ⇒ Connection

Returns a new instance of Connection.



7
8
9
10
# File 'lib/ably/realtime/connection.rb', line 7

def initialize(client)
  @client         = client
  @message_serial = 0
end

Instance Method Details

#connection_completedObject



27
28
29
30
31
32
# File 'lib/ably/realtime/connection.rb', line 27

def connection_completed
  trigger :connecting

  start_tls if client.use_tls?
  driver.start
end

#post_initObject

EventMachine::Connection interface



21
22
23
24
25
# File 'lib/ably/realtime/connection.rb', line 21

def post_init
  trigger :initalised

  setup_driver
end

#receive_data(data) ⇒ Object



34
35
36
# File 'lib/ably/realtime/connection.rb', line 34

def receive_data(data)
  driver.parse(data)
end

#send(protocol_message) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/ably/realtime/connection.rb', line 12

def send(protocol_message)
  add_message_serial_if_ack_required_to(protocol_message) do
    protocol_message = Models::ProtocolMessage.new(protocol_message)
    client.log_http("Prot msg sent =>: #{protocol_message.action_sym} #{protocol_message.to_json}")
    driver.text(protocol_message.to_json)
  end
end

#unbindObject



38
39
40
# File 'lib/ably/realtime/connection.rb', line 38

def unbind
  trigger :disconnected
end

#urlObject

WebSocket::Driver interface



43
44
45
46
47
# File 'lib/ably/realtime/connection.rb', line 43

def url
  URI(client.endpoint).tap do |endpoint|
    endpoint.query = URI.encode_www_form(client.auth.auth_params.merge(timestamp: as_since_epoch(Time.now), binary: false))
  end.to_s
end

#write(data) ⇒ Object



49
50
51
# File 'lib/ably/realtime/connection.rb', line 49

def write(data)
  send_data(data)
end