lib/submodules/ably-ruby/lib/ably/realtime/connection.rb in ably-rest-1.0.6 vs lib/submodules/ably-ruby/lib/ably/realtime/connection.rb in ably-rest-1.1.0

- old
+ new

@@ -77,10 +77,13 @@ max_connection_state_ttl: nil, # allow a max TTL to be passed in, usually for CI test purposes thus overiding any connection_state_ttl sent from Ably realtime_request_timeout: 10, # default timeout when establishing a connection, or sending a HEARTBEAT, CONNECT, ATTACH, DETACH or CLOSE ProtocolMessage websocket_heartbeats_disabled: false, }.freeze + # Max number of messages to bundle in a single ProtocolMessage + MAX_PROTOCOL_MESSAGE_BATCH_SIZE = 50 + # A unique public identifier for this connection, used to identify this member in presence events and messages # @return [String] attr_reader :id # A unique private connection key used to recover this connection, assigned by Ably @@ -223,11 +226,11 @@ # # @return [Ably::Util::SafeDeferrable] # def ping(&block) if initialized? || suspended? || closing? || closed? || failed? - error = Ably::Models::ErrorInfo.new(message: "Cannot send a ping when the connection is #{state}", code: 80003) + error = Ably::Models::ErrorInfo.new(message: "Cannot send a ping when the connection is #{state}", code: Ably::Exceptions::Codes::DISCONNECTED) return Ably::Util::SafeDeferrable.new_and_fail_immediately(logger, error) end Ably::Util::SafeDeferrable.new(logger).tap do |deferrable| started = nil @@ -254,20 +257,20 @@ end once_or_if([:suspended, :closing, :closed, :failed]) do next if finished finished = true - deferrable.fail Ably::Models::ErrorInfo.new(message: "Ping failed as connection has changed state to #{state}", code: 80003) + deferrable.fail Ably::Models::ErrorInfo.new(message: "Ping failed as connection has changed state to #{state}", code: Ably::Exceptions::Codes::DISCONNECTED) end EventMachine.add_timer(defaults.fetch(:realtime_request_timeout)) do next if finished finished = true __incoming_protocol_msgbus__.unsubscribe(:protocol_message, &wait_for_ping) error_msg = "Ping timed out after #{defaults.fetch(:realtime_request_timeout)}s" logger.warn { error_msg } - deferrable.fail Ably::Models::ErrorInfo.new(message: error_msg, code: 50003) + deferrable.fail Ably::Models::ErrorInfo.new(message: error_msg, code: Ably::Exceptions::Codes::TIMEOUT_ERROR) safe_yield block, nil if block_given? end end end @@ -278,19 +281,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 Ably::Exceptions::ConnectionFailed.new("Unable to connect to #{url}", nil, 80000) + deferrable.fail Ably::Exceptions::ConnectionFailed.new("Unable to connect to #{url}", nil, Ably::Exceptions::Codes::CONNECTION_FAILED) 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 Ably::Exceptions::ConnectionFailed.new("Unexpected response from #{url} (#{http.response_header.status})", 400, 40000) + deferrable.fail Ably::Exceptions::ConnectionFailed.new("Unexpected response from #{url} (#{http.response_header.status})", 400, Ably::Exceptions::Codes::BAD_REQUEST) end end end end end