ably 0.8.4 → 0.8.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/Rakefile +1 -1
  4. data/lib/ably/auth.rb +23 -19
  5. data/lib/ably/models/token_details.rb +8 -6
  6. data/lib/ably/modules/conversions.rb +4 -0
  7. data/lib/ably/modules/state_emitter.rb +1 -1
  8. data/lib/ably/modules/uses_state_machine.rb +8 -1
  9. data/lib/ably/realtime/auth.rb +13 -13
  10. data/lib/ably/realtime/channel.rb +2 -2
  11. data/lib/ably/realtime/channel/channel_manager.rb +3 -3
  12. data/lib/ably/realtime/channel/channel_state_machine.rb +2 -1
  13. data/lib/ably/realtime/client/incoming_message_dispatcher.rb +13 -7
  14. data/lib/ably/realtime/client/outgoing_message_dispatcher.rb +6 -0
  15. data/lib/ably/realtime/connection.rb +4 -4
  16. data/lib/ably/realtime/connection/connection_manager.rb +9 -3
  17. data/lib/ably/realtime/connection/connection_state_machine.rb +1 -1
  18. data/lib/ably/realtime/presence.rb +4 -4
  19. data/lib/ably/rest/client.rb +2 -2
  20. data/lib/ably/version.rb +1 -1
  21. data/spec/acceptance/realtime/auth_spec.rb +9 -9
  22. data/spec/acceptance/realtime/channel_history_spec.rb +2 -2
  23. data/spec/acceptance/realtime/channel_spec.rb +13 -12
  24. data/spec/acceptance/realtime/channels_spec.rb +6 -2
  25. data/spec/acceptance/realtime/client_spec.rb +4 -3
  26. data/spec/acceptance/realtime/connection_failures_spec.rb +21 -15
  27. data/spec/acceptance/realtime/connection_spec.rb +31 -27
  28. data/spec/acceptance/realtime/message_spec.rb +31 -24
  29. data/spec/acceptance/realtime/presence_history_spec.rb +2 -2
  30. data/spec/acceptance/realtime/presence_spec.rb +10 -11
  31. data/spec/acceptance/realtime/stats_spec.rb +1 -1
  32. data/spec/acceptance/realtime/time_spec.rb +1 -1
  33. data/spec/acceptance/rest/auth_spec.rb +77 -46
  34. data/spec/acceptance/rest/channel_spec.rb +22 -3
  35. data/spec/acceptance/rest/client_spec.rb +6 -6
  36. data/spec/acceptance/rest/presence_spec.rb +9 -7
  37. data/spec/support/event_machine_helper.rb +30 -4
  38. data/spec/support/protocol_helper.rb +9 -6
  39. data/spec/unit/auth_spec.rb +1 -1
  40. data/spec/unit/models/token_details_spec.rb +8 -0
  41. data/spec/unit/modules/async_wrapper_spec.rb +1 -1
  42. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85089829c198d66df277d8b4c675497c3632ed88
4
- data.tar.gz: c6a05542c8c35adce99763b651290cb3e5fbf472
3
+ metadata.gz: deb69100f880e16767da5cad8178d7ed8ec8202a
4
+ data.tar.gz: f9c6e5b632f1992657178b118c80e4b828de051c
5
5
  SHA512:
6
- metadata.gz: b13264f6a68b29dcb4ccd0f7bc87af4df57cfb9d685bd7f87ebda5bef3c7679a437dd2ee5f967e0eb2385ab3659588784b32ae6f39520931723e1407d9471b2a
7
- data.tar.gz: 5d5f15f00cce1ddced2188d2e3c5a8c3f1b36a719d281b54738eded944db6127e5546df65048118935d35ee6ea8b588ceab2cadb4f8ac66d0998a609e5aaba54
6
+ metadata.gz: d725527fdd9e8c517233bebdc87f3bd8775234c1cbf9f44a8ff7ce8c28de744fe4037f67fbdae26caae83428c7785116056f4289c60c342d9b7df7a533913b07
7
+ data.tar.gz: d2b8f496227bf4122e167426380213de6473f89c02385eadabd82d268fbe01b347fd9cf9b973f1dbce86b2b2e8beab0670221d8657367cef1ada68783367673e
data/README.md CHANGED
@@ -187,7 +187,7 @@ token_details = client.auth.request_token
187
187
  token_details.token # => "xVLyHw.CLchevH3hF....MDh9ZC_Q"
188
188
  client = Ably::Rest.new(token: token_details.token)
189
189
 
190
- token = client.auth.create_token_request(token_params: { ttl: 3600 })
190
+ token = client.auth.create_token_request(ttl: 3600)
191
191
  # => {"id"=>...,
192
192
  # "clientId"=>nil,
193
193
  # "ttl"=>3600,
data/Rakefile CHANGED
@@ -16,7 +16,7 @@ begin
16
16
  namespace :doc do
17
17
  desc 'Generate Markdown Specification from the RSpec public API tests'
18
18
  task :spec do
19
- ENV['TEST_LIMIT_PROTOCOLS'] = JSON.dump({ msgpack: 'JSON and MsgPack' })
19
+ ENV['PROTOCOL'] = 'json'
20
20
 
21
21
  rspec_task.rspec_opts = %w(
22
22
  --require ./spec/support/markdown_spec_formatter
@@ -43,11 +43,11 @@ module Ably
43
43
  # Creates an Auth object
44
44
  #
45
45
  # @param [Ably::Rest::Client] client {Ably::Rest::Client} this Auth object uses
46
- # @param [Hash] auth_options the authentication options used as a default future token requests
47
46
  # @param [Hash] token_params the token params used as a default for future token requests
47
+ # @param [Hash] auth_options the authentication options used as a default future token requests
48
48
  # @option (see #request_token)
49
49
  #
50
- def initialize(client, auth_options, token_params)
50
+ def initialize(client, token_params, auth_options)
51
51
  unless auth_options.kind_of?(Hash)
52
52
  raise ArgumentError, 'Expected auth_options to be a Hash'
53
53
  end
@@ -87,8 +87,8 @@ module Ably
87
87
  #
88
88
  # In the event that a new token request is made, the provided options are used.
89
89
  #
90
- # @param [Hash] auth_options the authentication options used for future token requests
91
90
  # @param [Hash] token_params the token params used for future token requests
91
+ # @param [Hash] auth_options the authentication options used for future token requests
92
92
  # @option auth_options [Boolean] :force obtains a new token even if the current token is valid
93
93
  # @option (see #request_token)
94
94
  #
@@ -100,12 +100,12 @@ module Ably
100
100
  # token_details = client.auth.authorise
101
101
  #
102
102
  # # will use token request from block to authorise if not already authorised
103
- # token_details = client.auth.authorise auth_callback: Proc.new do
103
+ # token_details = client.auth.authorise {}, auth_callback: Proc.new do
104
104
  # # create token_request object
105
105
  # token_request
106
106
  # end
107
107
  #
108
- def authorise(auth_options = {}, token_params = {})
108
+ def authorise(token_params = {}, auth_options = {})
109
109
  ensure_valid_auth_attributes auth_options
110
110
 
111
111
  auth_options = auth_options.clone
@@ -120,7 +120,7 @@ module Ably
120
120
  token_params = (auth_options.delete(:token_params) || {}).merge(token_params)
121
121
  @token_params = @token_params.merge(token_params) # update defaults
122
122
 
123
- @current_token_details = request_token(auth_options, token_params)
123
+ @current_token_details = request_token(token_params, auth_options)
124
124
  end
125
125
 
126
126
  # Request a {Ably::Models::TokenDetails} which can be used to make authenticated token based requests
@@ -143,15 +143,15 @@ module Ably
143
143
  # token_details = client.auth.request_token
144
144
  #
145
145
  # # token request with token params
146
- # client.auth.request_token token_params: { ttl: 1.hour }
146
+ # client.auth.request_token ttl: 1.hour
147
147
  #
148
148
  # # token request using auth block
149
- # token_details = client.auth.request_token auth_callback: Proc.new do
149
+ # token_details = client.auth.request_token {}, auth_callback: Proc.new do
150
150
  # # create token_request object
151
151
  # token_request
152
152
  # end
153
153
  #
154
- def request_token(auth_options = {}, token_params = {})
154
+ def request_token(token_params = {}, auth_options = {})
155
155
  ensure_valid_auth_attributes auth_options
156
156
 
157
157
  token_params = (auth_options[:token_params] || {}).merge(token_params)
@@ -163,7 +163,7 @@ module Ably
163
163
  elsif auth_url = auth_options.delete(:auth_url)
164
164
  token_request_from_auth_url(auth_url, auth_options)
165
165
  else
166
- create_token_request(auth_options, token_params)
166
+ create_token_request(token_params, auth_options)
167
167
  end
168
168
 
169
169
  case token_request
@@ -186,12 +186,6 @@ module Ably
186
186
 
187
187
  # Creates and signs a token request that can then subsequently be used by any client to request a token
188
188
  #
189
- # @param [Hash] auth_options the authentication options for the token request
190
- # @option auth_options [String] :key API key comprising the key name and key secret in a single string
191
- # @option auth_options [String] :client_id client ID identifying this connection to other clients (will use +client_id+ specified when library was instanced if provided)
192
- # @option auth_options [Boolean] :query_time when true will query the {https://www.ably.io Ably} system for the current time instead of using the local time
193
- # @option auth_options [Hash] :token_params convenience to pass in +token_params+ within the +auth_options+ argument, this helps avoid the following +authorise({key: key}, {ttl: 23})+ by allowing +authorise(key:key,token_params:{ttl:23})+
194
- #
195
189
  # @param [Hash] token_params the token params used in the token request
196
190
  # @option token_params [String] :client_id A client ID to associate with this token. The generated token may be used to authenticate as this +client_id+
197
191
  # @option token_params [Integer] :ttl validity time in seconds for the requested {Ably::Models::TokenDetails}. Limits may apply, see {https://www.ably.io/documentation/other/authentication}
@@ -199,10 +193,16 @@ module Ably
199
193
  # @option token_params [Time] :timestamp the time of the request
200
194
  # @option token_params [String] :nonce an unquoted, unescaped random string of at least 16 characters
201
195
  #
196
+ # @param [Hash] auth_options the authentication options for the token request
197
+ # @option auth_options [String] :key API key comprising the key name and key secret in a single string
198
+ # @option auth_options [String] :client_id client ID identifying this connection to other clients (will use +client_id+ specified when library was instanced if provided)
199
+ # @option auth_options [Boolean] :query_time when true will query the {https://www.ably.io Ably} system for the current time instead of using the local time
200
+ # @option auth_options [Hash] :token_params convenience to pass in +token_params+ within the +auth_options+ argument, especially useful when setting default token_params in the client constructor
201
+ #
202
202
  # @return [Models::TokenRequest]
203
203
  #
204
204
  # @example
205
- # client.auth.create_token_request(id: 'asd.asd', token_params: { ttl: 3600 })
205
+ # client.auth.create_token_request({ ttl: 3600 }, { id: 'asd.asd' })
206
206
  # #<Ably::Models::TokenRequest:0x007fd5d919df78
207
207
  # # @hash={
208
208
  # # :id=>"asds.adsa",
@@ -214,7 +214,7 @@ module Ably
214
214
  # # :mac=>"881oZHeFo6oMim7....uE56a8gUxHw="
215
215
  # # }
216
216
  # #>>
217
- def create_token_request(auth_options = {}, token_params = {})
217
+ def create_token_request(token_params = {}, auth_options = {})
218
218
  ensure_valid_auth_attributes auth_options
219
219
 
220
220
  auth_options = auth_options.clone
@@ -401,7 +401,11 @@ module Ably
401
401
 
402
402
  # Returns the current token if it exists or authorises and retrieves a token
403
403
  def token_auth_string
404
- if token
404
+ # If a TokenDetails object has been issued by this library
405
+ # then that Token will take precedence
406
+ if @current_token_details
407
+ authorise.token
408
+ elsif token # token string was configured in the options
405
409
  token
406
410
  else
407
411
  authorise.token
@@ -34,7 +34,7 @@ module Ably::Models
34
34
  # @param attributes
35
35
  # @option attributes [String] :token token used to authenticate requests
36
36
  # @option attributes [String] :key_name API key name used to create this token
37
- # @option attributes [Time,Integer] :issued Time the token was issued as Time or Integer in milliseconds
37
+ # @option attributes [Time,Integer] :issued Time the token was issued as Time or Integer in milliseconds
38
38
  # @option attributes [Time,Integer] :expires Time the token expires as Time or Integer in milliseconds
39
39
  # @option attributes [String] :capability JSON stringified capabilities assigned to this token
40
40
  # @option attributes [String] :client_id client ID assigned to this token
@@ -52,31 +52,31 @@ module Ably::Models
52
52
  # @!attribute [r] token
53
53
  # @return [String] Token used to authenticate requests
54
54
  def token
55
- hash.fetch(:token)
55
+ hash[:token]
56
56
  end
57
57
 
58
58
  # @!attribute [r] key_name
59
59
  # @return [String] API key name used to create this token. An API key is made up of an API key name and secret delimited by a +:+
60
60
  def key_name
61
- hash.fetch(:key_name)
61
+ hash[:key_name]
62
62
  end
63
63
 
64
64
  # @!attribute [r] issued
65
65
  # @return [Time] Time the token was issued
66
66
  def issued
67
- as_time_from_epoch(hash.fetch(:issued), granularity: :ms)
67
+ as_time_from_epoch(hash[:issued], granularity: :ms, allow_nil: :true)
68
68
  end
69
69
 
70
70
  # @!attribute [r] expires
71
71
  # @return [Time] Time the token expires
72
72
  def expires
73
- as_time_from_epoch(hash.fetch(:expires), granularity: :ms)
73
+ as_time_from_epoch(hash[:expires], granularity: :ms, allow_nil: :true)
74
74
  end
75
75
 
76
76
  # @!attribute [r] capability
77
77
  # @return [Hash] Capabilities assigned to this token
78
78
  def capability
79
- JSON.parse(hash.fetch(:capability))
79
+ JSON.parse(hash.fetch(:capability)) if hash.fetch(:capability)
80
80
  end
81
81
 
82
82
  # @!attribute [r] client_id
@@ -86,9 +86,11 @@ module Ably::Models
86
86
  end
87
87
 
88
88
  # Returns true if token is expired or about to expire
89
+ # For tokens that have not got an explicit expires attribute expired? will always return true
89
90
  #
90
91
  # @return [Boolean]
91
92
  def expired?
93
+ return false if !expires
92
94
  expires < Time.now + TOKEN_EXPIRY_BUFFER
93
95
  end
94
96
 
@@ -6,6 +6,8 @@ module Ably::Modules
6
6
 
7
7
  private
8
8
  def as_since_epoch(time, options = {})
9
+ return nil if options[:allow_nil] && !time
10
+
9
11
  granularity = options.fetch(:granularity, :ms)
10
12
 
11
13
  case time
@@ -19,6 +21,8 @@ module Ably::Modules
19
21
  end
20
22
 
21
23
  def as_time_from_epoch(time, options = {})
24
+ return nil if options[:allow_nil] && !time
25
+
22
26
  granularity = options.fetch(:granularity, :ms)
23
27
 
24
28
  case time
@@ -142,7 +142,7 @@ module Ably::Modules
142
142
  def deferrable_for_state_change_to(target_state)
143
143
  Ably::Util::SafeDeferrable.new(logger).tap do |deferrable|
144
144
  fail_proc = Proc.new do |state_change|
145
- deferrable.fail self, state_change.reason
145
+ deferrable.fail state_change.reason
146
146
  end
147
147
  once_or_if(target_state, else: fail_proc) do
148
148
  yield self if block_given?
@@ -86,13 +86,20 @@ module Ably::Modules
86
86
  module ClassMethods
87
87
  def emits_klass
88
88
  @emits_klass ||= if @emits_klass_name
89
- Object.const_get @emits_klass_name
89
+ get_const(@emits_klass_name)
90
90
  end
91
91
  end
92
92
 
93
93
  def ensure_state_machine_emits(klass)
94
94
  @emits_klass_name = klass
95
95
  end
96
+
97
+ def get_const(klass_name)
98
+ klass_names = klass_name.split('::')
99
+ klass_names.inject(Kernel) do |klass, name|
100
+ klass.const_get(name)
101
+ end
102
+ end
96
103
  end
97
104
  end
98
105
  end
@@ -65,9 +65,9 @@ module Ably
65
65
  # token_details #=> Ably::Models::TokenDetails
66
66
  # end
67
67
  #
68
- def authorise(auth_options = {}, token_params = {}, &success_callback)
68
+ def authorise(token_params = {}, auth_options = {}, &success_callback)
69
69
  async_wrap(success_callback) do
70
- auth_sync.authorise(auth_options, token_params)
70
+ auth_sync.authorise(token_params, auth_options)
71
71
  end
72
72
  end
73
73
 
@@ -76,8 +76,8 @@ module Ably
76
76
  # @option (see Ably::Auth#authorise)
77
77
  # @return [Ably::Models::TokenDetails]
78
78
  #
79
- def authorise_sync(auth_options = {}, token_params = {})
80
- auth_sync.authorise(auth_options, token_params)
79
+ def authorise_sync(token_params = {}, auth_options = {})
80
+ auth_sync.authorise(token_params, auth_options)
81
81
  end
82
82
 
83
83
  # def_delegator :auth_sync, :request_token, :request_token_sync
@@ -100,9 +100,9 @@ module Ably
100
100
  # token_details #=> Ably::Models::TokenDetails
101
101
  # end
102
102
  #
103
- def request_token(auth_options = {}, token_params = {}, &success_callback)
103
+ def request_token(token_params = {}, auth_options = {}, &success_callback)
104
104
  async_wrap(success_callback) do
105
- request_token_sync(auth_options, token_params)
105
+ request_token_sync(token_params, auth_options)
106
106
  end
107
107
  end
108
108
 
@@ -111,8 +111,8 @@ module Ably
111
111
  # @option (see Ably::Auth#authorise)
112
112
  # @return [Ably::Models::TokenDetails]
113
113
  #
114
- def request_token_sync(auth_options = {}, token_params = {})
115
- auth_sync.request_token(auth_options, token_params)
114
+ def request_token_sync(token_params = {}, auth_options = {})
115
+ auth_sync.request_token(token_params, auth_options)
116
116
  end
117
117
 
118
118
  # Creates and signs a token request that can then subsequently be used by any client to request a token
@@ -124,12 +124,12 @@ module Ably
124
124
  # @yield [Models::TokenRequest]
125
125
  #
126
126
  # @example
127
- # client.auth.create_token_request(id: 'asd.asd', ttl: 3600) do |token_request|
127
+ # client.auth.create_token_request({ ttl: 3600 }, id: 'asd.asd') do |token_request|
128
128
  # token_request #=> Ably::Models::TokenRequest
129
129
  # end
130
- def create_token_request(auth_options = {}, token_params = {}, &success_callback)
130
+ def create_token_request(token_params = {}, auth_options = {}, &success_callback)
131
131
  async_wrap(success_callback) do
132
- create_token_request_sync(auth_options, token_params)
132
+ create_token_request_sync(token_params, auth_options)
133
133
  end
134
134
  end
135
135
 
@@ -138,8 +138,8 @@ module Ably
138
138
  # @option (see Ably::Auth#authorise)
139
139
  # @return [Ably::Models::TokenRequest]
140
140
  #
141
- def create_token_request_sync(auth_options = {}, token_params = {})
142
- auth_sync.create_token_request(auth_options, token_params)
141
+ def create_token_request_sync(token_params = {}, auth_options = {})
142
+ auth_sync.create_token_request(token_params, auth_options)
143
143
  end
144
144
 
145
145
  # Auth header string used in HTTP requests to Ably
@@ -134,7 +134,7 @@ module Ably
134
134
  # puts "#{message.name} event received with #{message.data}"
135
135
  # end
136
136
  #
137
- # channel.publish('click', 'body').errback do |message, error|
137
+ # channel.publish('click', 'body').errback do |error, message|
138
138
  # puts "#{message.name} was not received, error #{error.message}"
139
139
  # end
140
140
  #
@@ -155,7 +155,7 @@ module Ably
155
155
  end
156
156
 
157
157
  queue_messages(messages).tap do |deferrable|
158
- deferrable.callback &success_block if block_given?
158
+ deferrable.callback(&success_block) if block_given?
159
159
  end
160
160
  end
161
161
 
@@ -77,10 +77,10 @@ module Ably::Realtime
77
77
  def nack_messages(protocol_message, error)
78
78
  (protocol_message.messages + protocol_message.presence).each do |message|
79
79
  logger.debug "Calling NACK failure callbacks for #{message.class.name} - #{message.to_json}, protocol message: #{protocol_message}"
80
- message.fail message, error
80
+ message.fail error
81
81
  end
82
82
  logger.debug "Calling NACK failure callbacks for #{protocol_message.class.name} - #{protocol_message.to_json}"
83
- protocol_message.fail protocol_message, error
83
+ protocol_message.fail error
84
84
  end
85
85
 
86
86
  def drop_pending_queue_from_ack(ack_protocol_message)
@@ -146,7 +146,7 @@ module Ably::Realtime
146
146
  end
147
147
 
148
148
  connection.unsafe_on(:failed) do |error|
149
- if can_transition_to?(:failed)
149
+ if can_transition_to?(:failed) && !channel.detached?
150
150
  channel.transition_state_machine :failed, reason: Ably::Exceptions::ConnectionFailed.new('Connection failed', nil, 80002, error)
151
151
  end
152
152
  end
@@ -22,8 +22,9 @@ module Ably::Realtime
22
22
 
23
23
  transition :from => :initialized, :to => [:attaching]
24
24
  transition :from => :attaching, :to => [:attached, :detaching, :failed]
25
- transition :from => :attached, :to => [:detaching, :failed]
25
+ transition :from => :attached, :to => [:detaching, :detached, :failed]
26
26
  transition :from => :detaching, :to => [:detached, :attaching, :failed]
27
+ transition :from => :detached, :to => [:attaching, :attached, :failed]
27
28
  transition :from => :failed, :to => [:attaching]
28
29
 
29
30
  after_transition do |channel, transition|
@@ -68,7 +68,13 @@ module Ably::Realtime
68
68
 
69
69
  when ACTION.Connect
70
70
  when ACTION.Connected
71
- connection.transition_state_machine :connected, reason: protocol_message.error, protocol_message: protocol_message unless connection.connected?
71
+ if connection.disconnected? || connection.closing? || connection.closed? || connection.failed?
72
+ logger.debug "Incoming CONNECTED ProtocolMessage discarded as connection has moved on and is in state: #{connection.state}"
73
+ elsif connection.connected?
74
+ logger.error "CONNECTED ProtocolMessage should not have been received when the connection is in the CONNECTED state"
75
+ else
76
+ connection.transition_state_machine :connected, reason: protocol_message.error, protocol_message: protocol_message
77
+ end
72
78
 
73
79
  when ACTION.Disconnect, ACTION.Disconnected
74
80
  connection.transition_state_machine :disconnected, reason: protocol_message.error unless connection.disconnected?
@@ -163,17 +169,17 @@ module Ably::Realtime
163
169
  def nack_messages(messages, protocol_message)
164
170
  messages.each do |message|
165
171
  logger.debug "Calling NACK failure callbacks for #{message.class.name} - #{message.to_json}, protocol message: #{protocol_message}"
166
- message.fail message, protocol_message.error
172
+ message.fail protocol_message.error
167
173
  end
168
174
  end
169
175
 
170
176
  def drop_pending_queue_from_ack(ack_protocol_message)
171
177
  message_serial_up_to = ack_protocol_message.message_serial + ack_protocol_message.count - 1
172
- connection.__pending_message_ack_queue__.drop_while do |protocol_message|
173
- if protocol_message.message_serial <= message_serial_up_to
174
- yield protocol_message
175
- true
176
- end
178
+
179
+ while !connection.__pending_message_ack_queue__.empty?
180
+ next_message = connection.__pending_message_ack_queue__.first
181
+ return if next_message.message_serial > message_serial_up_to
182
+ yield connection.__pending_message_ack_queue__.shift
177
183
  end
178
184
  end
179
185
 
@@ -44,6 +44,12 @@ module Ably::Realtime
44
44
 
45
45
  non_blocking_loop_while(condition) do
46
46
  protocol_message = outgoing_queue.shift
47
+
48
+ if (!connection.transport)
49
+ protocol_message.fail Ably::Exceptions::TransportClosed.new('Transport disconnected unexpectedly', nil, 80003)
50
+ next
51
+ end
52
+
47
53
  current_transport_outgoing_message_bus.publish :protocol_message, protocol_message
48
54
 
49
55
  if protocol_message.ack_required?
@@ -119,7 +119,7 @@ module Ably
119
119
  # the failed state. Once closed, the library will not attempt to re-establish the
120
120
  # connection without a call to {Connection#connect}.
121
121
  #
122
- # @yield [Ably::Realtime::Connection] block is called as soon as this connection is in the Closed state
122
+ # @yield block is called as soon as this connection is in the Closed state
123
123
  #
124
124
  # @return [EventMachine::Deferrable]
125
125
  #
@@ -134,7 +134,7 @@ module Ably
134
134
  # Causes the library to attempt connection. If it was previously explicitly
135
135
  # closed by the user, or was closed as a result of an unrecoverable error, a new connection will be opened.
136
136
  #
137
- # @yield [Ably::Realtime::Connection] block is called as soon as this connection is in the Connected state
137
+ # @yield block is called as soon as this connection is in the Connected state
138
138
  #
139
139
  # @return [EventMachine::Deferrable]
140
140
  #
@@ -190,7 +190,7 @@ module Ably
190
190
  EventMachine::HttpRequest.new(url).get.tap do |http|
191
191
  http.errback do
192
192
  yield false if block_given?
193
- deferrable.fail "Unable to connect to #{url}"
193
+ deferrable.fail Ably::Exceptions::ConnectionFailed.new("Unable to connect to #{url}", nil, 80000)
194
194
  end
195
195
  http.callback do
196
196
  EventMachine.next_tick do
@@ -199,7 +199,7 @@ module Ably
199
199
  if result
200
200
  deferrable.succeed
201
201
  else
202
- deferrable.fail "Unexpected response from #{url} (#{http.response_header.status})"
202
+ deferrable.fail Ably::Exceptions::ConnectionFailed.new("Unexpected response from #{url} (#{http.response_header.status})", 400, 40000)
203
203
  end
204
204
  end
205
205
  end