lib/submodules/ably-ruby/lib/ably/realtime/connection.rb in ably-rest-0.8.3 vs lib/submodules/ably-ruby/lib/ably/realtime/connection.rb in ably-rest-0.8.5
- old
+ new
@@ -53,10 +53,11 @@
:closed,
:failed
)
include Ably::Modules::StateEmitter
include Ably::Modules::UsesStateMachine
+ ensure_state_machine_emits 'Ably::Models::ConnectionStateChange'
# Expected format for a connection recover key
RECOVER_REGEX = /^(?<recover>[\w-]+):(?<connection_serial>\-?\w+)$/
# A unique public identifier for this connection, used to identify this member in presence events and messages
@@ -116,11 +117,11 @@
# Causes the connection to close, entering the closed state, from any state except
# the failed state. Once closed, the library will not attempt to re-establish the
# connection without a call to {Connection#connect}.
#
- # @yield [Ably::Realtime::Connection] block is called as soon as this connection is in the Closed state
+ # @yield block is called as soon as this connection is in the Closed state
#
# @return [EventMachine::Deferrable]
#
def close(&success_block)
unless closing? || closed?
@@ -131,11 +132,11 @@
end
# Causes the library to attempt connection. If it was previously explicitly
# closed by the user, or was closed as a result of an unrecoverable error, a new connection will be opened.
#
- # @yield [Ably::Realtime::Connection] block is called as soon as this connection is in the Connected state
+ # @yield block is called as soon as this connection is in the Connected state
#
# @return [EventMachine::Deferrable]
#
def connect(&success_block)
unless connecting? || connected?
@@ -187,19 +188,19 @@
url = "http#{'s' if client.use_tls?}:#{Ably::INTERNET_CHECK.fetch(:url)}"
EventMachine::DefaultDeferrable.new.tap do |deferrable|
EventMachine::HttpRequest.new(url).get.tap do |http|
http.errback do
yield false if block_given?
- deferrable.fail "Unable to connect to #{url}"
+ deferrable.fail Ably::Exceptions::ConnectionFailed.new("Unable to connect to #{url}", nil, 80000)
end
http.callback do
EventMachine.next_tick do
result = http.response_header.status == 200 && http.response.strip == Ably::INTERNET_CHECK.fetch(:ok_text)
yield result if block_given?
if result
deferrable.succeed
else
- deferrable.fail "Unexpected response from #{url} (#{http.response_header.status})"
+ deferrable.fail Ably::Exceptions::ConnectionFailed.new("Unexpected response from #{url} (#{http.response_header.status})", 400, 40000)
end
end
end
end
end