# Connection
## Connection PropertiesARTConnection PropertiesAbly::Realtime::Connection Attributesio.ably.lib.realtime.Connection MembersIO.Ably.Realtime.Connection Properties
The `Connection` object exposes the following public propertiesattributesmembers:
### idId
A unique public identifier `String` for this connection, used to identify this member in presence events and messages.
### stateState
The current [`io.ably.lib.realtime.ConnectionState`](#connection-state) `state`[`IO.Ably.Realtime.ConnectionState`](#connection-state) `state`[`Ably::Realtime::Connection::STATE`](#connection-state) `state`[`ARTRealtimeConnectionState`](#connection-state) `state``state String` of this Connection. See the [`Connection` states](https://ably.com/docs/connect/states.md#connection-states) for more information.
### errorReasonreasonErrorReasonerror_reason
When a connection failure occurs this attributememberproperty contains the [`ErrorInfo`](https://ably.com/docs/api/realtime-sdk/types.md#error-info)[`AblyException`](https://ably.com/docs/api/realtime-sdk/types.md#ably-exception).
### keyKey
A unique private connection key `String` used to recover or resume a connection, assigned by Ably. When recovering a connection explicitly, the `recoveryKey``recovery_key` is used in the `recover` [client options](https://ably.com/docs/api/realtime-sdk.md#client-options) as it contains both the `key` and the last message `serial`.
This private connection key can also be used by other REST clients to publish on behalf of this client. See the [publishing over REST on behalf of a realtime client documentation](https://ably.com/docs/pub-sub/advanced.md#publish-on-behalf) for more info.
### recoveryKeyrecovery_keyRecoveryKey
The recovery key `String` can be used by another client to recover this connection's state in the `recover``Recover` [client options](https://ably.com/docs/api/realtime-sdk.md#client-options) propertymemberattribute. See [connection state recover options](https://ably.com/docs/connect/states.md#connection-state-recover-options) for more information.
### serialSerial
The serial number `Integer` of the last message to be received on this connection, used automatically by the library when recovering or resuming a connection. When recovering a connection explicitly, the `recoveryKey``recovery_key``RecoveryKey` is used in the `recover``Recover` [client options](https://ably.com/docs/api/realtime-sdk.md#client-options) as it contains both the `key` and the last message `serial`.
## Connection MethodsARTConnection MethodsAbly::Realtime::Connection Methodsio.ably.lib.realtime.Connection MethodsIO.Ably.Realtime.Connection Methods
### connectConnect
`connect(): void`
`Deferrable connect -> yields Connection`
`void connect()`
`void Connect()`
`Future connect()`
Explicitly calling `connect``Connect` is unnecessary unless the [`ClientOptions`](https://ably.com/docs/api/realtime-sdk/types.md#client-options) attribute `autoConnect``auto_connect``AutoConnect` is `false`. Unless already `connected` or `connecting`, this method causes the connection to open, entering the `connecting` state.
#### Returns
A [`Deferrable`](https://ably.com/docs/api/realtime-sdk/types.md#deferrable) object is returned from this method.
On successfully connecting to Ably, the registered success blocks for the [`Deferrable`](https://ably.com/docs/api/realtime-sdk/types.md#deferrable) and any block provided to this method yields a [`Connection`](https://ably.com/docs/api/realtime-sdk/connection.md) object.
Failure to connect will trigger the errback callbacks of the [`Deferrable`](https://ably.com/docs/api/realtime-sdk/types.md#deferrable) with an [`ErrorInfo`](#error-info) object containing an error response as defined in the [Ably REST API](https://ably.com/docs/api/rest-api.md#common) documentation.
#### Returns
`Future`
Failure to connect will throw an `AblyException` with an [`errorInfo`](#error-info) property containing an error response as defined in the [Ably REST API](https://ably.com/docs/api/rest-api.md#common) documentation.
### closeClose
`close(): void`
`Deferrable close -> yields Connection`
`void close()`
`void Close()`
`Future close()`
Causes the connection to close, entering the `closing` state. Once `closed`, the library will not attempt to re-establish the connection without an explicit call to [`connect()`](#connect)[`Connect()`](#connect)[`connect`](#connect).
#### Returns
A [`Deferrable`](https://ably.com/docs/api/realtime-sdk/types.md#deferrable) object is returned from this method.
On successfully closing the connection, the registered success blocks for the [`Deferrable`](https://ably.com/docs/api/realtime-sdk/types.md#deferrable) and any block provided to this method yields a [`Connection`](https://ably.com/docs/api/realtime-sdk/connection.md) object.
Failure to close the connection will trigger the errback callbacks of the [`Deferrable`](https://ably.com/docs/api/realtime-sdk/types.md#deferrable) with an [`ErrorInfo`](#error-info) object containing an error response as defined in the [Ably REST API](https://ably.com/docs/api/rest-api.md#common) documentation.
### onOn
There are threetwo overloaded versions of this method:
`on(String event, listener(ConnectionStateChange stateChange))`
`on(ConnectionEvent *event) -> yields ConnectionStateChange`
`void on(ConnectionEvent event, ConnectionStateListener listener)`
`on(event: ARTRealtimeConnectionEvent, call: (ARTConnectionStateChange?) -> Void) -> ARTEventListener`
`void On(ConnectionEvent event, Action action)`
`Stream on(ably.ConnectionStateChange stateChange)`
The Stream returned can be subscribed for with a listener.
`final streamSubscription = stream.listen(listener)`
Register the given listener blockfunctionactionlistener for the specified [`ConnectionEvent`](#connection-event) on the `Connection`. The listener is passed a [ConnectionStateChange](#connection-state-change) object that contains the current state, previous state, and an optional reason for the event or state change.
`on(String[] events, listener(ConnectionStateChange stateChange))`
Same as above, but registers multiple listeners, one for each event in the array.
`on(listener(ConnectionStateChange stateChange))`
`on -> yields ConnectionStateChange`
`void on(ConnectionStateListener listener)`
`on(call: (ARTConnectionStateChange?) -> Void) -> ARTEventListener`
`void On(Action action)`
`Stream on()`
The Stream returned can be subscribed for with a listener.
`final streamSubscription = stream.listen(listener)`
Register the given listener blockfunctionactionlistener for all [ConnectionEvents](#connection-event) on the `Connection`. The listener is passed a [ConnectionStateChange](#connection-state-change) object that contains the current state, previous state, the event, and an optional reason for the event or state change. (For the `update` event, the current and previous states will be the same).
If an exception is thrown in the listener and bubbles up to the event emitter, it will be caught and logged at `error` level, so as not to affect other listeners for the same event
#### Parameters
| Parameter | Description | Type |
|-----------|-------------|------|
| event | the connection event to subscribe to | [`ConnectionEvent`](#connection-event) |
| Parameter | Description | Type |
|-----------|-------------|------|
| event(s)event | the connection event(s) to subscribe tothe connection event to subscribe tothe connection event as a Symbol such as `:connected` or `ConnectionEvent` object to subscribe to | `String` or `String[]`[`ConnectionEvent`](#connection-event)[`ConnectionEvent`](#connection-event)[`ARTRealtimeConnectionEvent`](#connection-event) |
| listenerlisteneraction&blockcall | is a function of the form `function(stateChange)` to be notified for matching eventslistener to be notified for matching eventsaction to be executed for matching eventslistener block that is yielded to for matching eventscalled with matching events | function[`ConnectionStateListener`](#connection-state-listener)[`ConnectionStateChange`](#connection-state-listener)blockfunction |
### onceOnce
There are two overloaded versions of this method:
`once(String event, listener(ConnectionStateChange stateChange))`
`once(ConnectionEvent *event) -> yields ConnectionStateChange`
`void once(ConnectionEvent event, ConnectionStateListener listener)`
`once(event: ARTRealtimeConnectionEvent, call: (ARTConnectionStateChange?) -> Void) -> ARTEventListener`
`void Once(ConnectionEvent event, Action action)`
Register the given listener blockfunctionactionlistener for a single occurrence of the specified [ConnectionEvent](#connection-event) on the `Connection`. Once the listener has been called, it is removed as a registered listener and will not be called again. The listener is passed a [ConnectionStateChange](#connection-state-change) object that contains the current state, previous state, the event, and an optional reason for the state change. (For the `update` event, the current and previous states will be the same).
`once(listener(ConnectionStateChange stateChange))`
`once -> yields ConnectionStateChange`
`void once(ConnectionStateListener listener)`
`once(call: (ARTConnectionStateChange?) -> Void) -> ARTEventListener`
`void Once(Action action)`
Register the given listener blockactionlistener for a single occurrence of any [ConnectionEvent](#connection-event) on the `Connection`. Once the listener has been called, it is removed as a registered listener and will not be called again. The listener is passed a [ConnectionStateChange](#connection-state-change) object that contains the current state, previous state, and an optional reason for the state change. (For the `update` event, the current and previous states will be the same).
If an exception is thrown in the listener and bubbles up to the event emitter, it will be caught and logged at `error` level, so as not to affect other listeners for the same event
#### Parameters
| Parameter | Description | Type |
|-----------|-------------|------|
| event(s)event | the connection event(s) to subscribe tothe connection event to subscribe tothe connection event as a Symbol such as `:connected` or `ConnectionEvent` object to subscribe to | `String` or `String[]`[`ConnectionEvent`](#connection-event)[`ConnectionEvent`](#connection-event)[`ARTRealtimeConnectionEvent`](#connection-event) |
| listenerlisteneraction&blockcall | is a function of the form `function(stateChange)` to be notified for a single occurrence of a matching eventlistener to be notified for a single occurrence of a matching state changeaction to be executed for matching state changeslistener block that is yielded to for a single occurrence of a matching eventcalled with matching events | function[`ConnectionStateListener`](#connection-state-listener)[`ConnectionStateChange`](#connection-state-listener)blockfunction |
### offOff
There are sixtwo overloaded versions of this method:
`off(String event, listener)`
`off(ConnectionEvent *event, &block)`
`void off(ConnectionEvent event, ConnectionStateListener listener)`
`off(event: ARTRealtimeConnectionEvent, listener: ARTEventListener)`
`void Off(ConnectionEvent event, Action action)`
Remove the given listener blockactionlistener for the [ConnectionEvent](#connection-event).
`off(listener)`
`off(&block)`
`void off(ConnectionStateListener listener)`
`off(listener: ARTEventListener)`
`void Off(Action action)`
Remove the given listener blockactionlistener for all [ConnectionEvents](#connection-event)
`off(String[] states, listener)`
Removes the given listener from all [ConnectionEvents](#connection-event) in the array.
`off(String state)`
Removes all listeners for a given [`ConnectionEvent`s.](#connection-event)
`off(String[] states)`
Removes all listeners for all [ConnectionEvents](#connection-event) in the array.
`off()`
Removes all listeners (including both those registered against specific events and those registered without an event).
#### Parameters
| Parameter | Description | Type |
|-----------|-------------|------|
| event(s)event | the connection event(s) to unsubscribe fromthe connection event to unsubscribe fromthe connection event to subscribe tothe connection event as a Symbol such as `:connected` or `ConnectionEvent` object to unsubscribe from | `String` or `String[]`[`ConnectionEvent`](#connection-event)[`ConnectionEvent`](#connection-event)[`ARTRealtimeConnectionEvent`](#connection-event) |
| listeneraction&block | is the listener function to be removedis the listener to be removedaction to be executed for matching event changesis the listener block to be removedprevious return value from a `on` or `once` call | function[`ConnectionStateListener`](#connection-state-listener)[`ConnectioneventChangeEventArgs`](#connection-state-listener)blockARTEventListener |
`streamSubscription` obtained from calling `on` can be used to cancel a listener by calling `streamSubscription.cancel`.
### pingPing
`ping(callback(ErrorInfo err, Number responseInMilliseconds))`
`ping(): Promise`
`Deferrable ping -> yields Float seconds`
`void ping(CompletionListener listener)`
`ping(callback: (ARTErrorInfo?) -> Void)`
`void Ping(Action callback)`
When connected, sends a heartbeat ping to the Ably server and executes the callback with any error and the response time in millisecondsexecutes the callbackcalls the listeneryields the elapsed time in seconds when a heartbeat ping request is echoed from the server. This can be useful for measuring true round-trip latency to the connected Ably server.
#### Returns
Returns a promise. On success, the promise resolves with a number representing the time in seconds for the heartbeat ping request to be echoed. On failure, the promise is rejected with an [`ErrorInfo`](https://ably.com/docs/api/realtime-sdk/types.md#error-info) object that details the reason why it was rejected.
#### Returns
A [`Deferrable`](https://ably.com/docs/api/realtime-sdk/types.md#deferrable) object is returned from this method.
On successfully echoing a heartbeat from Ably, the registered success blocks for the [`Deferrable`](https://ably.com/docs/api/realtime-sdk/types.md#deferrable) and any block provided to this method yields a `Float` representing the time in seconds for the heartbeat ping request to be echoed.
Failure to receive a heartbeat ping will trigger the errback callbacks of the [`Deferrable`](https://ably.com/docs/api/realtime-sdk/types.md#deferrable) with an [`ErrorInfo`](#error-info) object containing an error response as defined in the [Ably REST API](https://ably.com/docs/api/rest-api.md#common) documentation.
### listeners
`listeners(eventName?): null | connectionEventCallback[]`
Returns the listeners for the specified [`ConnectionEvent`](#connection-event).
### whenState
`whenState(targetState): Promise`
If the connection is already in a given state, returns a promise which immediately resolves to `null`. Otherwise calls [`once`](#once) to return a promise which resolves the next time the connection transitions to the given state.
#### Parameters
| Parameter | Description | Type |
|-----------|-------------|------|
| targetState | The [`ConnectionState`](#connection-state) to wait for | `ConnectionState` |
#### Returns
Returns a promise. If the connection is already in the given state, the promise will immediately resolve to `null`. If not, it will call [`once()`](#once) to return a promise which resolves the next time the connection transitions to the given state.
### createRecoveryKey
`createRecoveryKey(): null | string`
Generates a string that can be used by another client to recover the current connection's state using the `recover` property of the [`ClientOptions`](https://ably.com/docs/api/realtime-sdk/types.md#client-options) object. See [connection state recover options](https://ably.com/connect/states#connection-state-recover-options) for more information.
## Related types
### io.ably.lib.realtime.CompletionListener
A `io.ably.lib.realtime.CompletionListener` is an interface allowing a client to be notified of the outcome of an asynchronous operation.
```java
public interface CompletionListener {
// Called when the associated operation completes successfully,
public void onSuccess();
// Called when the associated operation completes with an error.
public void onError(ErrorInfo reason);
}
```
### ConnectionStateARTRealtimeConnectionStateConnection::STATE Enumio.ably.lib.realtime.ConnectionState EnumIO.Ably.Realtime.ConnectionState Enumably.ConnectionState Enum
`ConnectionState` is a String with a value matching any of the [`Realtime Connection` states](https://ably.com/docs/connect/states.md).
```javascript
var ConnectionStates = [
'initialized',
'connecting',
'connected',
'disconnected',
'suspended',
'closing',
'closed',
'failed'
]
```
`io.ably.lib.realtime.ConnectionState` is an enum representing all the [`Realtime Connection` states](https://ably.com/docs/connect/states.md).
```java
public enum ConnectionState {
initialized, // 0
connecting, // 1
connected, // 2
disconnected, // 3
suspended, // 4
closing, // 5
closed, // 6
failed // 7
}
```
`IO.Ably.Realtime.ConnectionState` is an enum representing all the [`Realtime Connection` states](https://ably.com/docs/connect/states.md).
```csharp
public enum ConnectionState
{
Initialized, //0
Connecting, //1
Connected, //2
Disconnected, //3
Suspended, //4
Closing, //5
Closed, //6
Failed //7
};
```
`Ably::Realtime::Connection::STATE` is an enum-like value representing all the [`Realtime Connection` states](https://ably.com/docs/connect/states.md). `STATE` can be represented interchangeably as either symbols or constants.
#### Symbol states
```ruby
:initialized # => 0
:connecting # => 1
:connected # => 2
:disconnected # => 3
:suspended # => 4
:closing # => 5
:closed # => 6
:failed # => 7
```
#### Constant states
```ruby
Connection::STATE.Initialized # => 0
Connection::STATE.Connecting # => 1
Connection::STATE.Connected # => 2
Connection::STATE.Disconnected # => 3
Connection::STATE.Suspended # => 4
Connection::STATE.Closing # => 5
Connection::STATE.Closed # => 6
Connection::STATE.Failed # => 7
```
#### Example usage
```ruby
# Example with symbols
client.connection.on(:connected) { ... }
# Example with constants
client.connection.on(Ably::Realtime::Connection::STATE.Connected) { ... }
# Interchangeable
Ably::Realtime::Connection::STATE.Connected == :connected # => true
```
`ARTRealtimeConnectionState` is an enum representing all the [`Realtime Connection` states](https://ably.com/docs/connect/states.md).
```objc
typedef NS_ENUM(NSUInteger, ARTRealtimeConnectionState) {
ARTRealtimeInitialized,
ARTRealtimeConnecting,
ARTRealtimeConnected,
ARTRealtimeDisconnected,
ARTRealtimeSuspended,
ARTRealtimeClosing,
ARTRealtimeClosed,
ARTRealtimeFailed
};
```
```swift
public enum ARTRealtimeConnectionState : UInt {
case Initialized
case Connecting
case Connected
case Disconnected
case Suspended
case Closing
case Closed
case Failed
}
```
`ably.ConnectionState` is an enum representing all the [`Realtime Connection` states](https://ably.com/docs/connect/states.md).
```flutter
enum ConnectionState {
initialized,
connecting,
connected,
disconnected,
suspended,
closing,
closed,
failed
}
```
### ConnectionEventARTRealtimeConnectionEventConnection::EVENT Enumio.ably.lib.realtime.ConnectionEvent EnumIO.Ably.Realtime.ConnectionEvent Enumably.ConnectionEvent Enum
`ConnectionEvent` is a String that can be emitted as an event on the `Connection` object; either a [`Realtime Connection` state](https://ably.com/docs/connect/states.md) or an `update` event.
```javascript
var ConnectionEvents = [
'initialized',
'connecting',
'connected',
'disconnected',
'suspended',
'closing',
'closed',
'failed',
'update'
]
```
`io.ably.lib.realtime.ConnectionEvent` is an enum representing all the events that can be emitted be the `Connection`; either a [`Realtime Connection` state](https://ably.com/docs/connect/states.md) or an `update` event.
```java
public enum ConnectionEvent {
initialized, // 0
connecting, // 1
connected, // 2
disconnected, // 3
suspended, // 4
closing, // 5
closed, // 6
failed, // 7
update // 8
}
```
`IO.Ably.Realtime.ConnectionEvent` is an enum representing all the events that can be emitted be the `Connection`; either a [`Realtime Connection` state](https://ably.com/docs/connect/states.md) or an `Update` event.
```csharp
public enum ConnectionState
{
Initialized, //0
Connecting, //1
Connected, //2
Disconnected, //3
Suspended, //4
Closing, //5
Closed, //6
Failed, //7
update //8
};
```
`Ably::Realtime::Connection::EVENT` is an enum-like value representing all the events that can be emitted be the `Connection`; either a [`Realtime Connection` state](https://ably.com/docs/connect/states.md) or an `:update` event. `EVENT` can be represented interchangeably as either symbols or constants.
#### Symbol states
```ruby
:initialized # => 0
:connecting # => 1
:connected # => 2
:disconnected # => 3
:suspended # => 4
:closing # => 5
:closed # => 6
:failed # => 7
:update # => 8
```
#### Constant states
```ruby
Connection::EVENT.Initialized # => 0
Connection::EVENT.Connecting # => 1
Connection::EVENT.Connected # => 2
Connection::EVENT.Disconnected # => 3
Connection::EVENT.Suspended # => 4
Connection::EVENT.Closing # => 5
Connection::EVENT.Closed # => 6
Connection::EVENT.Failed # => 7
Connection::EVENT.Update # => 8
```
#### Example usage
```ruby
# Example with symbols
client.connection.on(:connected) { ... }
# Example with constants
client.connection.on(Ably::Realtime::Connection::STATE.Connected) { ... }
# Interchangeable
Ably::Realtime::Connection::STATE.Connected == :connected # => true
```
`ARTRealtimeConnectionEvent` is an enum representing all the events that can be emitted be the `Connection`; either a [`Realtime Connection` state](https://ably.com/docs/connect/states.md) or an `Update` event.
```objc
typedef NS_ENUM(NSUInteger, ARTRealtimeConnectionEvent) {
ARTRealtimeConnectionEventInitialized,
ARTRealtimeConnectionEventConnecting,
ARTRealtimeConnectionEventConnected,
ARTRealtimeConnectionEventDisconnected,
ARTRealtimeConnectionEventSuspended,
ARTRealtimeConnectionEventClosing,
ARTRealtimeConnectionEventClosed,
ARTRealtimeConnectionEventFailed,
ARTRealtimeConnectionEventUpdate
};
```
```swift
public enum ARTRealtimeConnectionEvent : UInt {
case Initialized
case Connecting
case Connected
case Disconnected
case Suspended
case Closing
case Closed
case Failed
case Update
}
```
`ably.ConnectionEvent` is an enum representing all the events that can be emitted be the `Connection`; either a [`Realtime Connection` state](https://ably.com/docs/connect/states.md) or an `update` event.
```flutter
enum ConnectionEvent {
initialized,
connecting,
connected,
disconnected,
suspended,
closing,
closed,
failed,
update
}
```
### io.ably.lib.realtime.ConnectionStateListener
A `io.ably.lib.realtime.ConnectionStateListener` is an interface allowing a client to be notified of connection state change. See [`Connection#on`](https://ably.com/docs/api/realtime-sdk/connection.md#on) to register a listener for one or more events.
```java
public interface ConnectionStateListener {
// Called when the connection state changes
public void onConnectionStateChanged(ConnectionStateListener.ConnectionStateChange state);
}
```
### ConnectionStateChange ObjectARTConnectionStateChangeio.ably.lib.realtime.ConnectionStateListener.ConnectionStateChangeConnectionStateChangeIO.Ably.Realtime.ConnectionStateChangeably.ConnectionStateChange
A `io.ably.lib.realtime.ConnectionStateListener.ConnectionStateChange``Ably::Models::ConnectionStateChange``ARTConnectionStateChange``IO.Ably.Realtime.ConnectionStateChange``ConnectionStateChange` is a type encapsulating state change information emitted by the [`Connection`](https://ably.com/docs/api/realtime-sdk/connection.md) object. See [`Connection#on`](https://ably.com/docs/api/realtime-sdk/connection.md#on) to register a listener for one or more events.
#### PropertiesMembersAttributes
| Property | Description | Type |
|----------|-------------|------|
| currentCurrent | the new state | [State `String`](https://ably.com/docs/api/realtime-sdk/types.md#connection-state)[`Connection::STATE`](https://ably.com/docs/api/realtime-sdk/types.md#connection-state)[`ConnectionState`](https://ably.com/docs/api/realtime-sdk/types.md#connection-state) |
| previousPrevious | the previous state. (for the `update` event, this will be equal to the `current` state) | [State `String`](https://ably.com/docs/api/realtime-sdk/types.md#connection-state)[`Connection::STATE`](https://ably.com/docs/api/realtime-sdk/types.md#connection-state)[`ConnectionState`](https://ably.com/docs/api/realtime-sdk/types.md#connection-state) |
| eventEvent | the event that triggered this state change | [`ConnectionEvent`Connection::EVENT](https://ably.com/docs/api/realtime-sdk/types.md#connection-event) |
| reasonReason | an [`ErrorInfo`](#error-info) containing any information relating to the transition | [`ErrorInfo`](https://ably.com/docs/api/realtime-sdk/types.md#error-info) |
| retryInretry_inRetryIn | Duration upon which the library will retry a connection where applicable, as millisecondssecondsa `Timespan` | `Integer``Timespan``Long Integer` |
### LastConnectionDetails
A `LastConnectionDetails` object provides details on the last connection in a browser environment persisted when the `window beforeunload` fired. This object is provided to the callback specified in the `recover` attribute of [`ClientOptions`](https://ably.com/docs/api/realtime-sdk/types.md#client-options). The callback in turn instructs the client library whether the connection should be recovered or not. See [connection state recovery](https://ably.com/docs/connect/states.md) for more information.
Please note that as [`sessionStorage`](https://www.w3.org/TR/webstorage/) is used to persist the `LastConnectionDetails` between page reloads, it is only available for pages in the same origin and top-level browsing context.
#### Properties
| Property | Description | Type |
|----------|-------------|------|
| recoveryKey | An opaque string obtained from the [recoveryKey](https://ably.com/docs/api/realtime-sdk/connection.md#recovery-key) attribute of the [Connection object](https://ably.com/docs/api/realtime-sdk/connection.md) before the page was unloaded. This property is used by the library to recover the connection | `String` |
| disconnectedAt | the time at which the previous library was abruptly disconnected before the page was unloaded. This is represented as milliseconds since epoch | `Integer` |
| location | a clone of [`location`](https://www.w3.org/TR/html5/browsers.html#the-location-interface) object of the previous page's `document` object before the page was unloaded. A common use case for this attribute is to ensure that the previous page URL is the same as the current URL before allowing the connection to be recovered. For example, you may want the connection to be recovered only for page reloads, but not when a user navigates to a different page | `String` |
| clientId | the [`clientId`](https://ably.com/docs/api/realtime-sdk/authentication.md#client-id) of the [client's Auth object](https://ably.com/docs/api/realtime-sdk/authentication.md) before the page was unloaded. A common use case for this attribute is to ensure that the current logged in user's `clientId` matches the previous connection's `clientId` before allowing the connection to be recovered. Ably prohibits changing a `clientId` for an existing connection, so any mismatch in `clientId` during a recover will result in the connection moving to the failed state | `String` |