Skip to content

Commit

Permalink
Setting connection resume/recover based on message received
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed May 17, 2024
1 parent ad66ec6 commit 997256c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/ably/realtime/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class Client

# When a recover option is specified a connection inherits the state of a previous connection that may have existed under a different instance of the Realtime library, please refer to the API documentation for further information on connection state recovery
# @return [String,Nil]
attr_reader :recover
attr_accessor :recover

# Additional parameters to be sent in the querystring when initiating a realtime connection
# @return [Hash]
Expand Down
8 changes: 8 additions & 0 deletions lib/ably/realtime/connection/connection_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ def connected(protocol_message)
# Update the connection details and any associated defaults
connection.set_connection_details protocol_message.connection_details

is_connection_resume_or_recover_attempt = !connection.key.nil? || !client.recover.nil?
# RTN15c7, RTN16d
failed_resume_or_recover = !protocol_message.connection_id == connection.id && !protocol_message.error.nil?
if is_connection_resume_or_recover_attempt and failed_resume_or_recover # RTN15c7
connection.message_serial = 0
end
client.recover = nil # RTN16k, explicitly setting null, so it won't be used for subsequent connection requests

if connection.key
if protocol_message.connection_id == connection.id
logger.debug { "ConnectionManager: Connection resumed successfully - ID #{connection.id} and key #{connection.key}" }
Expand Down

0 comments on commit 997256c

Please sign in to comment.