lib/submodules/ably-ruby/lib/ably/realtime/connection.rb in ably-rest-0.8.6 vs lib/submodules/ably-ruby/lib/ably/realtime/connection.rb in ably-rest-0.8.9

- old
+ new

@@ -56,11 +56,11 @@ 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+)$/ + RECOVER_REGEX = /^(?<recover>[\w!-]+):(?<connection_serial>\-?\w+)$/ # Defaults for automatic connection recovery and timeouts DEFAULTS = { disconnected_retry_timeout: 15, # when the connection enters the DISCONNECTED state, after this delay in milliseconds, if the state is still DISCONNECTED, the client library will attempt to reconnect automatically suspended_retry_timeout: 30, # when the connection enters the SUSPENDED state, after this delay in milliseconds, if the state is still SUSPENDED, the client library will attempt to reconnect automatically @@ -82,10 +82,14 @@ # When a connection failure occurs this attribute contains the Ably Exception # @return [Ably::Models::ErrorInfo,Ably::Exceptions::BaseAblyException] attr_reader :error_reason + # Connection details of the currently established connection + # @return [Ably::Models::ConnectionDetails] + attr_reader :details + # {Ably::Realtime::Client} associated with this connection # @return [Ably::Realtime::Client] attr_reader :client # Underlying socket transport used for this connection, for internal use by the client library @@ -176,16 +180,16 @@ succeed_callback = deferrable.method(:succeed) fail_callback = deferrable.method(:fail) once(:connected) do deferrable.succeed - off &fail_callback + off(&fail_callback) end once(:failed, :closed, :closing) do deferrable.fail - off &succeed_callback + off(&succeed_callback) end end end # Sends a ping to Ably and yields the provided block when a heartbeat ping request is echoed from the server. @@ -354,14 +358,14 @@ # @param [Ably::Models::ProtocolMessage] protocol_message # @return [void] # @api private def send_protocol_message(protocol_message) add_message_serial_if_ack_required_to(protocol_message) do - Ably::Models::ProtocolMessage.new(protocol_message, logger: logger).tap do |protocol_message| - add_message_to_outgoing_queue protocol_message - notify_message_dispatcher_of_new_message protocol_message - logger.debug("Connection: Prot msg queued =>: #{protocol_message.action} #{protocol_message}") + Ably::Models::ProtocolMessage.new(protocol_message, logger: logger).tap do |message| + add_message_to_outgoing_queue message + notify_message_dispatcher_of_new_message message + logger.debug("Connection: Prot msg queued =>: #{message.action} #{message}") end end end # @api private @@ -435,10 +439,15 @@ # @api private def clear_error_reason @error_reason = nil end + # @api private + def set_connection_details(connection_details) + @details = connection_details + end + # Executes registered callbacks for a successful connection resume event # @api private def resumed resume_callbacks.each(&:call) end @@ -474,10 +483,12 @@ # # A client serial number therefore does not guarantee a message has been received, only sent. # A connection serial guarantees the server has received the message and is thus used for connection # recovery and resumes. # @return [Integer] starting at -1 indicating no messages sent, 0 when the first message is sent - attr_reader :client_serial + def client_serial + @client_serial + end def resume_callbacks @resume_callbacks ||= [] end