lib/syncano/sync_connection.rb in syncano-3.1.1.beta vs lib/syncano/sync_connection.rb in syncano-3.1.1.beta2
- old
+ new
@@ -19,17 +19,19 @@
# Eventmachine callback invoked after completing connection
def connection_completed
start_tls
end
- # Eventmachine callback invoked completing ssl handshake
+ # Eventmachine callback invoked after completing ssl handshake
def ssl_handshake_completed
auth_data = {
api_key: client.api_key,
instance: client.instance_name
}
+ auth_data[:auth_key] = client.auth_key if client.auth_key.present?
+
client.connection = self
send_data "#{auth_data.to_json}\n"
end
@@ -45,10 +47,12 @@
callbacks_queue.each do |callback_name|
callbacks[callback_name].call(notification)
end
elsif packet.call_response?
queue_response(packet)
+ elsif packet.auth?
+ queue_response(packet)
end
end
# Appends callback method to the end of callbacks chain
# @param [Symbol, String] callback_name
@@ -75,31 +79,31 @@
# Gets call response packet from the responses queue
# @param [Integer, String] message_id
# @return [Syncano::Packets::CallResponse]
def get_response(message_id)
- responses.delete(message_id)
+ responses.delete(message_id.to_s)
end
private
attr_accessor :client, :callbacks, :callbacks_queue, :responses, :responses_queue
# Adds call response packet to the responses queue
# @param [Syncano::Packets::CallResponse] packet
def queue_response(packet)
prune_responses_queue
- message_id = packet.message_id.to_i
+ message_id = packet.message_id.to_s
responses[message_id] = packet
- responses_queue << message_id
+ responses_queue << message_id.to_s
end
# Removes old call response packets from the responses queue
def prune_responses_queue
while !responses_queue.empty?
message_id = responses_queue.first
- if responses_queue[message_id].nil? || Time.now - responses[message_id].timestamp.to_time > 2.minutes
+ if responses[message_id].nil? || Time.now - responses[message_id].timestamp.to_time > 2.minutes
responses_queue.shift
responses.delete(message_id)
else
break
end
\ No newline at end of file