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

- old
+ new

@@ -233,11 +233,11 @@ started = nil finished = false ping_id = SecureRandom.hex(16) heartbeat_action = Ably::Models::ProtocolMessage::ACTION.Heartbeat - wait_for_ping = Proc.new do |protocol_message| + wait_for_ping = lambda do |protocol_message| next if finished if protocol_message.action == heartbeat_action && protocol_message.id == ping_id finished = true __incoming_protocol_msgbus__.unsubscribe(:protocol_message, &wait_for_ping) time_passed = Time.now.to_f - started.to_f @@ -421,13 +421,16 @@ echo: client.echo_messages, v: Ably::PROTOCOL_VERSION, lib: client.rest_client.lib_version_id, ) - # Use native websocket heartbeats if possible - # TODO: Fix once https://github.com/ably/ably-ruby/issues/116 is resolved - url_params['heartbeats'] = 'true' # unless defaults.fetch(:websocket_heartbeats_disabled) + # Use native websocket heartbeats if possible, but allow Ably protocol heartbeats + url_params['heartbeats'] = if defaults.fetch(:websocket_heartbeats_disabled) + 'true' + else + 'false' + end url_params['clientId'] = client.auth.client_id if client.auth.has_client_id? if connection_resumable? url_params.merge! resume: key, connection_serial: serial @@ -577,11 +580,11 @@ @resume_callbacks ||= [] end def create_pub_sub_message_bus Ably::Util::PubSub.new( - coerce_into: Proc.new do |event| + coerce_into: lambda do |event| raise KeyError, "Expected :protocol_message, :#{event} is disallowed" unless event == :protocol_message :protocol_message end ) end @@ -613,11 +616,13 @@ end def connection_state_available? return true if connected? + return false if time_since_connection_confirmed_alive? > connection_state_ttl + details.max_idle_interval + connected_last = state_history.reverse.find { |connected| connected.fetch(:state) == :connected } - if connected_last.nil? || (connected_last.fetch(:transitioned_at) < Time.now - connection_state_ttl) + if connected_last.nil? false else true end end