Skip to content

Commit

Permalink
Updated connection id and key to be cleared as per connection states
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Dec 11, 2023
1 parent 943f757 commit 4a72ad6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/src/main/java/io/ably/lib/realtime/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,19 @@ public class Connection extends EventEmitter<ConnectionEvent, ConnectionStateLis
* See <a href="https://ably.com/docs/realtime/connection#connection-state-recover-options">connection state recover options</a>
* for more information.
* <p>
* Spec: RTN16b, RTN16c
* Spec: RTN16m
* @deprecated use createRecoveryKey method instead.
*/
@Deprecated
public String recoveryKey;

/**
* createRecoveryKey is a method that returns a json string which incorporates the @connectionKey@, the
* current @msgSerial@, and a collection of pairs of channel @name@ and current @channelSerial@ for every
* currently attached channel.
* <p>
* Spec: RTN16g
*
* @return a json string which incorporates the @connectionKey@, the current @msgSerial@,
* and a collection of pairs of channel @name@ and current @channelSerial@ for every currently attached channel.
* </p>
*/
public String createRecoveryKey() {
if (key == null || key.isEmpty() || this.state == ConnectionState.closing ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,13 @@ private synchronized ConnectionStateChange setState(ITransport transport, StateI
ReconnectionStrategy.getRetryTime(ably.options.disconnectedRetryTimeout, ++disconnectedRetryAttempt);
}

// RTN8c, RTN9c
if (stateIndication.state == ConnectionState.closing || stateIndication.state == ConnectionState.closed
|| stateIndication.state == ConnectionState.suspended || stateIndication.state == ConnectionState.failed) {
connection.id = null;
connection.key = null;
}

/* update currentState */
ConnectionState newConnectionState = validatedStateIndication.state;
State newState = states.get(newConnectionState);
Expand Down

0 comments on commit 4a72ad6

Please sign in to comment.