# Constructor
## Constructor
The Ably Realtime library constructor is overloaded allowing it to be instantiated using a [`ClientOptions`](#client-options) object, or more simply using a string containing an [API key](https://ably.com/docs/auth/basic) or [Token](https://ably.com/docs/auth/token), as shown below:
`new Ably.Realtime(ClientOptions clientOptions)`
`Ably::Realtime.new(ClientOptions client_options)`
`new io.ably.lib.AblyRealtime(ClientOptions clientOptions)`
`new AblyRealtime(ClientOptions clientOptions)`
`(instancetype)initWithOptions:(ARTClientOptions *)options;`
`init(options: ARTClientOptions)`
`ably.Realtime(options: ClientOptions clientOptions)`
This will instantiate the library using the specified [ClientOptions](#client-options).
This will instantiate the library and create a new `Ably::Realtime::Client` using the specified [ClientOptions](#client-options).
`new Ably.Realtime(String keyOrTokenId)`
`Ably::Realtime.new(String key_or_token_id)`
`new io.ably.lib.AblyRealtime(String keyOrTokenIdString)`
`new AblyRealtime(string key)`
`(instancetype)initWithKey:(NSString *)key
(instancetype)initWithToken:(NSString *)token`
`init(key: String)
init(token: String)`
`ably.Realtime(key: String key)`
This will instantiate the Realtime library with the provided API key or Token ID string.
The Realtime constructor is used to instantiate the library. The Realtime library may be instantiated multiple times with the same or different [`ClientOptions`](#client-options) in any given context. Except where specified otherwise, instances operate independently of one another.
### Authentication
The Realtime library needs to have credentials to be able to authenticate with the Ably service. Ably supports both Basic and Token based authentication schemes. Read more on [authentication](https://ably.com/docs/auth).
#### Basic Authentication
You can pass a full-length API key in as `ClientOptions#key` (or just straight into the constructor instead of a `ClientOptions` instance), as obtained from the [application dashboard](https://ably.com/dashboard). Use this option if you wish to use [Basic authentication](https://ably.com/docs/auth/basic), or if you want to be able to [request Ably Tokens](https://ably.com/docs/auth/token) without needing to defer to a separate entity to sign [Ably TokenRequests](https://ably.com/docs/api/realtime-sdk/authentication#token-request). Note that initializing the library with a `key` does not necessarily mean that the library will use Basic auth; it is also able to create and sign Ably [TokenRequests](https://ably.com/docs/api/realtime-sdk/authentication#token-request), and can use token authentication for itself if it needs to or if [`ClientOptions#useTokenAuth`](#client-options) is enabled.
#### Token Authentication
The [`ClientOptions#token`](#client-options) option takes a `token` string or [`tokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) object, which may have been obtained from some other instance that requested the Ably Token. This option is rarely used in production since tokens are short-lived, so generally you would not start with a token without the means to refresh it. The [`authUrl` and `authCallback` options](#client-options) allow the library to request new Ably-compatible tokens or Ably TokenRequests as it needs to; using these options allows the library to be instantiated without a `key` or `token`, and an initial token will be obtained automatically when required.
The [`ClientOptions#token`](#client-options) option takes a `token` string or [tokenDetails](https://ably.com/docs/api/realtime-sdk/types#token-details) object, which may have been obtained from some other instance that requested the Ably Token. This option is rarely used in production since tokens are short-lived, so generally you would not start with a token without the means to refresh it. The [`AuthUrl` and `AuthCallback` options](#client-options) allow the library to request new Ably-compatible tokens or Ably TokenRequests as it needs to; using these options allows the library to be instantiated without a `Key` or `Token`, and an initial token will be obtained automatically when required.
The [`ClientOptions#token`](#client-options) option takes a `token` string or [tokenDetails](https://ably.com/docs/api/realtime-sdk/types#token-details) object, which may have been obtained from some other instance that requested the Ably Token. This option is rarely used in production since tokens are short-lived, so generally you would not start with a token without the means to refresh it. The [`:auth_url` and `:auth_callback` options](#client-options) allow the library to request new Ably-compatible tokens or Ably TokenRequests as it needs to; using these options allows the library to be instantiated without a `key` or `token`, and an initial token will be obtained automatically when required.
Read more on [authentication](https://ably.com/docs/auth).
### Thread safety
The Cocoa SDK makes the following thread safety guarantees:
- All public methods and properties can be safely accessed from any thread, both for reading and writing operations.
- Objects like `ARTTokenDetails` and message data returned by the SDK can be safely read from multiple threads. However, you should not modify these objects after they're created.
- Objects you pass to the library must not be mutated afterwards. Once passed to the SDK, treat them as immutable. You can safely read from them or pass them again, and the library will never modify them.
All internal operations are dispatched to a single serial GCD queue to ensure thread safety within the SDK. You can specify a custom queue for this using `ARTClientOptions.internalDispatchQueue`, but it must be serial to maintain thread safety guarantees.
All callbacks provided by you are dispatched to the main queue by default, allowing you to update UI directly without additional thread switching. You can specify a different queue using `ARTClientOptions.dispatchQueue`. The callback queue must be different from `ARTClientOptions.internalDispatchQueue` to prevent deadlocks. Using the same queue creates circular dependencies where internal operations wait for callbacks, while callbacks wait for the internal queue.
## Ably.Realtime Propertiesio.ably.lib.AblyRealtime MembersAbly::Realtime::Client AttributesARTRealtime PropertiesAblyRealtime Properties
The Realtime client exposes the following public attributesmembers:
The Realtime client exposes the following public properties:
### `Auth``auth`
A reference to the [Auth](https://ably.com/docs/api/realtime-sdk/authentication) authentication object configured for this client library.
### `push`
A reference to the [Push](https://ably.com/docs/push) object in this client library.
### `device`
A reference to the [LocalDevice](https://ably.com/docs/api/realtime-sdk/push#local-device) object.
A reference to the [ARTLocalDevice](https://ably.com/docs/api/realtime-sdk/push#local-device) object.
### `Channels``channels`
[Channels](https://ably.com/docs/api/realtime-sdk/channels#channels-object) is a reference to the [Channel](https://ably.com/docs/channels) collection instance for this library indexed by the channel name. You can use the [Get](https://ably.com/docs/api/realtime-sdk/channels#get) method of this to get a `Channel` instance. See [channels](https://ably.com/docs/channels) and [messages](https://ably.com/docs/channels/messages) for more information.
### `Connection``connection`
A reference to the [Connection](https://ably.com/docs/api/realtime-sdk/connection) object for this library instance.
### `rest_client`
A reference to the [REST Client](https://ably.com/docs/api/rest-sdk) configured with the same [ClientOptions](#client-options). The Realtime library is a super-set of the REST library, however accessing methods in the REST library, unlike the Realtime library, are blocking operations.
## Ably.Realtime Methodsio.ably.lib.AblyRealtime MethodsAbly::Realtime::Client MethodsARTRealtime MethodsAblyRealtime Methods
### Connectconnect
`connect(): void`
`connect(): void`
`Deferrable connect -> yields Connection`
`void connect()`
`connect(): void`
`void Connect()`
`connect(): void`
Explicitly calling `connect` is unnecessary unless the [ClientOptions](#client-options) `autoConnect` is disabled. This method calls `connection.connect()` and causes the connection to open, entering the `connecting` state.
Explicitly calling `connect` is unnecessary unless the [ClientOptions](#client-options) `auto_connect` is disabled. This method calls `connection.connect` and causes the connection to open, entering the `connecting` state.
Explicitly calling `Connect` is unnecessary unless the [ClientOptions](#client-options) `AuthConnect` is disabled. This method calls `connection.Connect()` and causes the connection to open, entering the `connecting` state.
#### Returns
A [Deferrable](https://ably.com/docs/api/realtime-sdk/types#deferrable) object is returned from this method.
On successfully connecting to Ably, the registered success callbacks for the [Deferrable](https://ably.com/docs/api/realtime-sdk/types#deferrable) and any block provided to this method yields a [Connection](https://ably.com/docs/api/realtime-sdk/connection) object.
Failure to connect will trigger the errback callbacks of the [Deferrable](https://ably.com/docs/api/realtime-sdk/types#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#common) documentation.
### Closeclose
`close(): void`
`close(): void`
`Deferrable close -> yields Connection`
`void close()`
`close(): void`
`void Close()`
`close(): void`
This calls `connection.close()` and 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()`.
This calls `connection.close` and 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`.
This calls `connection.Close()` and 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()`.
#### Returns
A [Deferrable](https://ably.com/docs/api/realtime-sdk/types#deferrable) object is returned from this method.
On successfully closing the connection, the registered success callbacks for the [Deferrable](https://ably.com/docs/api/realtime-sdk/types#deferrable) and any block provided to this method yields a [Connection](https://ably.com/docs/api/realtime-sdk/connection) object.
Failure to close the connection will trigger the errback callbacks of the [Deferrable](https://ably.com/docs/api/realtime-sdk/types#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#common) documentation.
### Statsstats
`stats(Object options, callback(ErrorInfo err, PaginatedResult results))`
`stats(Object params?): Promise>`
`stats(Object options, callback(ErrorInfo err, PaginatedResult results))`
`Deferrable stats(Hash options) ->; yields PaginatedResult;`
`PaginatedResult stats(Param[] options)`
`stats(query: ARTStatsQuery?, callback: (ARTPaginatedResult?, ARTErrorInfo?) -> Void) throws`
`Task> StatsAsync(StatsRequestParams query)`
This call queries the [REST `/stats` API](https://ably.com/docs/api/rest-api#stats) and retrieves your application's usage statistics. A [PaginatedResult](https://ably.com/docs/api/realtime-sdk/types#paginated-result) is returned, containing an array of [Stats](#stats-type) for the first page of results. [PaginatedResult](https://ably.com/docs/api/realtime-sdk/types#paginated-result) objects are iterable providing a means to page through historical statistics. [See an example set of raw stats returned via the REST API](https://ably.com/docs/metadata-stats/stats#metrics).
See [statistics](https://ably.com/docs/metadata-stats/stats) for more information.
#### Parameters
| Parameter | Description | Type |
|-----------|-------------|------|
| paramsoptionsquery | An optional object containing the query parameters used to specify which statistics are retrieved. If not specified the default parameters will be used | Object[`Param[]`](#param)`StatsRequestParams` |
| Parameter | Description | Type |
|-----------|-------------|------|
| options | An optional object containing the query parameters | Hash |
| &block | Yields a `PaginatedResult` object | Block |
| Parameter | Description | Type |
|-----------|-------------|------|
| query | An optional object containing the query parameters | `ARTStatsQuery` |
| callback | Called with a [ARTPaginatedResult](#paginated-result)<[ARTStats](https://ably.com/docs/api/rest-sdk/types#stats)> object or an error | Callback |
#### `options` parameters`ARTStatsQuery` properties`StatsRequestParams` properties`params` properties
The following options, as defined in the [REST `/stats` API](https://ably.com/docs/api/rest-api#stats) endpoint, are permitted:
| Property | Description | Type | Default |
|----------|-------------|------|---------|
| start:startStart | Earliest `DateTimeOffset` or `Time` or time in milliseconds since the epoch for any stats retrieved | `Long``Int` or `Time``DateTimeOffset``Number``Long` | beginning of time |
| end:endEnd | Latest `DateTimeOffset` or `Time` or time in milliseconds since the epoch for any stats retrieved | `Long``Int` or `Time``DateTimeOffset``Number``Long` | current time |
| direction:directionDirection | `:forwards` or `:backwards``forwards` or `backwards``forwards` or `backwards` | `String``Symbol``Direction` enum | backwards |
| limit:limitLimit | Maximum number of stats to retrieve up to 1,000 | `Integer``Number``Integer` | 100 |
| unit:unitUnit | `:minute`, `:hour`, `:day` or `:month`.`minute`, `hour`, `day` or `month`.`minute`, `hour`, `day` or `month`. Based on the unit selected, the given start or end times are rounded down to the start of the relevant interval depending on the unit granularity of the query | `String`[`StatsIntervalGranularity`](https://ably.com/docs/api/realtime-sdk/types#stats-granularity)[`ARTStatsGranularity`](#stats-granularity)`Symbol`[`StatsIntervalGranularity`](https://ably.com/docs/api/realtime-sdk/types#stats-granularity) enum | minute |
#### Returns
Returns a promise. On success, the promise is fulfilled with a [`PaginatedResult`](https://ably.com/docs/api/realtime-sdk/types#paginated-result) object containing an array of [`Stats`](https://ably.com/docs/api/realtime-sdk/types#stats) objects. On failure, the promise is rejected with an [`ErrorInfo`](https://ably.com/docs/api/realtime-sdk/types#error-info) object.
#### Callback result
On success, `result` contains a [`PaginatedResult`](#paginated-result) encapsulating an array of [`Stats`](https://ably.com/docs/api/realtime-sdk/types#stats) objects corresponding to the current page of results. [`PaginatedResult`](#paginated-result) supports pagination using [`next`](#paginated-result) and [`first`](#paginated-result) methods.
On failure to retrieve stats, `err` contains an [`ErrorInfo`](#error-info) object with an error response as defined in the [Ably REST API](https://ably.com/docs/api/rest-api#common) documentation.
#### Returns
On success, the returned [`PaginatedResult`](#paginated-result) encapsulates an array of [`Stats`](https://ably.com/docs/api/realtime-sdk/types#stats) objects corresponding to the current page of results. [`PaginatedResult`](#paginated-result) supports pagination using [`next`](#paginated-result) and [`first`](#paginated-result) methods.
Failure to retrieve the stats will raise an [`AblyException`](https://ably.com/docs/api/realtime-sdk/types#ably-exception)
#### Returns
Returns a `Task` which needs to be awaited.
On success, the returned [`PaginatedResult`](#paginated-result) encapsulates an array of [`Stats`](https://ably.com/docs/api/realtime-sdk/types#stats) objects corresponding to the current page of results. [`PaginatedResult`](#paginated-result) supports pagination using [`NextAsync`](#paginated-result) and [`FirstAsync`](#paginated-result) methods.
Failure to retrieve the stats will raise an [`AblyException`](https://ably.com/docs/api/realtime-sdk/types#ably-exception)
#### Returns
A [`Deferrable`](https://ably.com/docs/api/realtime-sdk/types#deferrable) object is returned from the stats method.
On success, the registered success callbacks for the [`Deferrable`](https://ably.com/docs/api/realtime-sdk/types#deferrable) and any block provided to the method yields a [PaginatedResult](#paginated-result) that encapsulates an array of [`Stats`](https://ably.com/docs/api/realtime-sdk/types#stats) objects corresponding to the current page of results. [`PaginatedResult`](#paginated-result) supports pagination using [`next`](#paginated-result) and [`first`](#paginated-result) methods.
Failure to retrieve the stats will trigger the errback callbacks of the [`Deferrable`](https://ably.com/docs/api/realtime-sdk/types#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#common) documentation.
### Timetime
`time(): Promise`
`time(callback(ErrorInfo err, Number time))`
`Deferrable time -> yields Time`
`long time()`
`Task; TimeAsync()`
`time(callback: (NSDate?, NSError?) -> Void)`
Obtains the time from the Ably service as a `Time` object. (Clients that do not have access to a sufficiently well maintained time source and wish to issue Ably [TokenRequests](https://ably.com/docs/api/realtime-sdk/authentication#token-request) with a more accurate timestamp should use the `queryTime` [clientOptions](#client-options) instead of this method).
Obtains the time from the Ably service as a `DateTimeOffset` object. (Clients that do not have access to a sufficiently well maintained time source and wish to issue Ably [TokenRequests](https://ably.com/docs/api/realtime-sdk/authentication#token-request) with a more accurate timestamp should use the `queryTime` [clientOptions](#client-options) instead of this method).
Obtains the time from the Ably service as milliseconds since epoch. (Clients that do not have access to a sufficiently well maintained time source and wish to issue Ably [TokenRequests](https://ably.com/docs/api/realtime-sdk/authentication#token-request) with a more accurate timestamp should use the `queryTime` [clientOptions](#client-options) instead of this method).
#### Returns
Returns a promise. On success, the promise is fulfilled with the time as milliseconds since the Unix epoch. On failure, the promise is rejected with an [ErrorInfo](https://ably.com/docs/api/realtime-sdk/types#error-info) object.
#### Callback result
On success, `time` is a number containing the number of milliseconds since the epoch.
On failure to retrieve the Ably server time, `err` contains an [ErrorInfo](#error-info) object with an error response as defined in the [Ably REST API](https://ably.com/docs/api/rest-api#common) documentation.
#### Returns
On success, milliseconds since the epoch is returned.
Failure to retrieve the Ably server time will raise an [AblyException](#ably-exception).
#### Returns
A `Task` is returned from this method.
When awaited on success it will return the server time converted to a `DateTimeOffset`.
Failure to retrieve the Ably server time will raise an [AblyException](#ably-exception).
#### Returns
A [Deferrable](https://ably.com/docs/api/realtime-sdk/types#deferrable) object is returned from this method.
On success, the registered success callbacks for the [Deferrable](https://ably.com/docs/api/realtime-sdk/types#deferrable) and any block provided to the method yields a `Time` object.
Failure to retrieve the Ably server time will trigger the errback callbacks of the [Deferrable](https://ably.com/docs/api/realtime-sdk/types#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#common) documentation.
### requestRequest
`request(method, path, version, params?, body?, headers?): Promise`
`request(String method, String path, Object params, Object body, Object headers, callback(ErrorInfo err, HttpPaginatedResponse results))`
`HttpPaginatedResponse request(String method, String path, Object params, Object body, Object headers)`
`HttpPaginatedResponse request(String method, String path, Object params, Object body, Object headers)`
`Task Request(string method, string path, Dictionary requestParams, JToken body, Dictionary headers)`
`request(method: String, path: String, params: Object?, body: Object?, headers: Object?, callback: (ARTHttpPaginatedResponse, ARTErrorInfo?) -> Void)`
Makes a REST request to a provided path. This is provided as a convenience for developers who wish to use REST API functionality that is either not documented or is not yet included in the public API, without having to handle authentication, paging, fallback hosts, MsgPack and JSON support, etc. themselves.
#### Parameters
| Parameter | Description | Type |
|-----------|-------------|------|
| method | Either `get`, `post`, `put`, `patch` or `delete` | String |
| path | The path to query | String |
| version | Version of the REST API to use | Number |
| params | (Optional) Any querystring parameters needed | Object |
| body | (Optional; for `post`, `put` and `patch` methods) The body of the request, as anything that can be serialized into JSON, such as an `Object` or `Array` | Serializable |
| headers | (Optional) Any headers needed. If provided, these will be mixed in with the default library headers | Object |
| Parameter | Description | Type |
|-----------|-------------|------|
| method | Either `get`, `post`, `put`, `patch` or `delete` | stringString |
| path | The path to query | stringString |
| params | (Optional) Any querystring parameters needed | `Dictionary`Object |
| body | (Optional; for `post`, `put` and `patch` methods) The body of the request, as a JTokenanything that can be serialized into JSON, such as an `Object` or `Array` | JTokenSerializable |
| headers | (Optional) Any headers needed. If provided, these will be mixed in with the default library headers | `Dictionary`Object |
#### Returns
Returns a promise. On success, the promise is fulfilled with the [`HttpPaginatedResponse`](https://ably.com/docs/api/realtime-sdk/types#http-paginated-response) object returned by the HTTP request. The response object will contain an empty or JSON-encodable object. On failure, the promise is rejected with an [`ErrorInfo`](https://ably.com/docs/api/realtime-sdk/types#error-info) object.
#### Callback result
On successfully receiving a response from Ably, `results` contains an `HttpPaginatedResponse``ARTHttpPaginatedResponse` [object](https://ably.com/docs/api/rest-sdk/types#http-paginated-response) containing the `statusCode` of the response, a `success` boolean (equivalent to whether the status code is between 200 and 299), `headers`, and an `items` array containing the current page of results. It supports pagination using [`next`](#paginated-result) and [`first`](#paginated-result) methods, identically to [`PaginatedResult`](https://ably.com/docs/api/rest-sdk/types#paginated-result).
On failure to obtain a response, `err` contains an [`ErrorInfo`](https://ably.com/docs/api/rest-sdk/types#error-info) object with an error response as defined in the [Ably REST API](https://ably.com/docs/api/rest-api#common) documentation. (Note that if a response is obtained, any response, even with a non-2xx status code, will result in an HTTP Paginated Response, not an `err`).
#### Returns
On successfully receiving a response from Ably, the returned [`HttpPaginatedResponse`](https://ably.com/docs/api/rest-sdk/types#http-paginated-response) contains a `status_code``statusCode` and a `success` boolean, `headers`, and an `items` array containing the current page of results. It supports pagination using [`next`](#paginated-result) and [`first`](#paginated-result) methods, identically to [`PaginatedResult`](https://ably.com/docs/api/rest-sdk/types#paginated-result).
Failure to obtain a response will raise an [`AblyException`](https://ably.com/docs/api/realtime-sdk/types#ably-exception). (Note that if a response is obtained, any response, even with a non-2xx status code, will result in an HTTP Paginated Response, not an exception).
#### Returns
The method is asynchronous and return a Task that has to be awaited to get the result.
On successfully receiving a response from Ably, the returned [`HttpPaginatedResponse`](https://ably.com/docs/api/rest-sdk/types#http-paginated-response) containing the `StatusCode` and a `Success` boolean, `Headers`, and an `Items` array containing the current page of results. [`HttpPaginatedResponse`](https://ably.com/docs/api/rest-sdk/types#http-paginated-response) supports pagination using [`NextAsync`](#paginated-result) and [`FirstAsync`](#paginated-result) methods.
Failure to obtain a response will raise an [`AblyException`](https://ably.com/docs/api/realtime-sdk/types#ably-exception). (Note that if a response is obtained, any response, even with a non-2xx status code, will result in an HTTP Paginated Response, not an exception).
#### Example
```javascript
const response = await rest.request(
'get',
'/channels/someChannel/messages',
3,
{ limit: 1, direction: 'forwards' },
);
console.log('Success! status code was ' + response.statusCode);
console.log(response.items.length + ' items returned');
if (response.hasNext()) {
const nextPage = await response.next();
console.log(nextPage.items.length + ' more items returned');
}
```
```nodejs
const response = await rest.request(
'get',
'/channels/someChannel/messages',
3,
{ limit: 1, direction: 'forwards' },
);
console.log('Success! status code was ' + response.statusCode);
console.log(response.items.length + ' items returned');
if (response.hasNext()) {
const nextPage = await response.next();
console.log(nextPage.items.length + ' more items returned');
}
```
### batchPublish
There are two overloaded versions of this method:
`batchPublish(BatchPublishSpec spec): Promise>`
Publishes a [BatchPublishSpec](#batch-publish-spec) object to one or more channels, up to a maximum of 100 channels.
`batchPublish(BatchPublishSpec[] specs): Promise[]>`
Publishes one or more [BatchPublishSpec](#batch-publish-spec) objects to one or more channels, up to a maximum of 100 channels.
#### Parameters
| Parameter | Description | Type |
|-----------|-------------|------|
| spec | An object describing the messages to be batch published and to which channels | [BatchPublishSpec](#batch-publish-spec) |
| specs | An array of objects describing the messages to be batch published and to which channels | [BatchPublishSpec[]](#batch-publish-spec) |
#### Returns
Returns a promise. On success, the promise is fulfilled with a [BatchResult](#batch-result) object, or an array of [BatchResult](#batch-result) objects, containing information about the result of the batch publish operation for each channel. The successful results of specific channels are returned as [BatchPublishSuccessResult](#batch-publish-success-result) objects, whilst failures are [BatchPublishFailureResult](#batch-publish-failure-result) objects. If an array of [BatchResult](#batch-result) objects are returned, they are in the same order as the provided [BatchPublishSpec](#batch-publish-spec). On failure, the promise is rejected with an [ErrorInfo](https://ably.com/docs/api/realtime-sdk/types#error-info) object.
### batchPresence
`batchPresence(String[] channels): Promise[]>`
Retrieves the presence state for one or more channels, up to a maximum of 100 channels. Presence state includes the [clientId](#client-options) of members and their current [PresenceAction](https://ably.com/docs/api/realtime-sdk/presence#presence-action).
#### Parameters
| Parameter | Description | Type |
|-----------|-------------|------|
| channels | An array of one or more channel names, up to a maximum of 100 channels | `String[]` |
#### Returns
Returns a promise. On success, the promise is fulfilled with a [BatchResult](#batch-result) object containing information about the result of the batch presence request for each channel. The successful results of specific channels are returned as [BatchPresenceSuccessResult](#batch-presence-success-result) objects, whilst failures are [BatchPresenceFailureResult](#batch-presence-failure-result) objects. On failure, the promise is rejected with an [ErrorInfo](https://ably.com/docs/api/realtime-sdk/types#error-info) object.
## Related types
### ARTClientOptionsio.ably.types.ClientOptionsIO.Ably.ClientOptionsably.ClientOptionsClientOptions
`ClientOptions` is a plain JavaScript object and is used in the `Ably.Realtime` constructor's `options` argument. The following attributes can be defined on the object:
`ClientOptions` is a Hash object and is used in the `Ably::Realtime` constructor's `options` argument. The following key symbol values can be added to the Hash:
`ART``ClientOptions` is used in the `AblyRealtime` constructor's `options` argument.
#### PropertiesMembersAttributesProperties
| Property | Description |
|----------|-------------|
| key | The full key string, as obtained from the [application dashboard](https://ably.com/dashboard). Use this option if you wish to use Basic authentication, or wish to be able to issue Ably Tokens without needing to defer to a separate entity to sign Ably TokenRequests. Read more about [Basic authentication](https://ably.com/docs/auth/basic)
**Type:** `String` |
| token | An authenticated [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) object, a [`TokenRequest`](https://ably.com/docs/api/realtime-sdk/types#token-request) object, or token string (obtained from the `token` property of a [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) component of an Ably TokenRequest response, or a [JSON Web Token](https://tools.ietf.org/html/rfc7519) satisfying [the Ably requirements for JWTs](https://ably.com/docs/auth/token#jwt)). This option is mostly useful for testing: since tokens are short-lived, in production you almost always want to use an authentication method that allows the client library to renew the token automatically when the previous one expires, such as `authUrl` or `authCallback`. Read more about [Token authentication](https://ably.com/docs/auth/token)
**Type:** `String`, `TokenDetails` or `TokenRequest` |
| authCallback | A function with the form `function(tokenParams, callback(err, tokenOrTokenRequest))` which is called when a new token is required. The role of the callback is to obtain a fresh token, one of: an Ably Token string (in plain text format); a signed [`TokenRequest`](https://ably.com/docs/api/realtime-sdk/types#token-request); a [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) (in JSON format); an [Ably JWT](https://ably.com/docs/api/realtime-sdk/authentication#ably-jwt). See [our authentication documentation](https://ably.com/docs/auth) for details of the Ably TokenRequest format and associated API calls
**Type:** `Callable` |
| authUrl | A URL that the library may use to obtain a fresh token, one of: an Ably Token string (in plain text format); a signed [`TokenRequest`](https://ably.com/docs/api/realtime-sdk/types#token-request); a [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) (in JSON format); an [Ably JWT](https://ably.com/docs/api/realtime-sdk/authentication#ably-jwt). For example, this can be used by a client to obtain signed Ably TokenRequests from an application server
**Type:** `String` |
| authMethod | The HTTP verb to use for the request, either `GET` or `POST`
**Type:** `String`
**Default:** `GET` |
| authHeaders | A set of key value pair headers to be added to any request made to the `authUrl`. Useful when an application requires these to be added to validate the request or implement the response. If the `authHeaders` object contains an `authorization` key, then `withCredentials` will be set on the xhr request
**Type:** `Object` |
| authParams | A set of key value pair params to be added to any request made to the `authUrl`. When the `authMethod` is `GET`, query params are added to the URL, whereas when `authMethod` is `POST`, the params are sent as URL encoded form data. Useful when an application require these to be added to validate the request or implement the response
**Type:** `Object` |
| tokenDetails | An authenticated [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) object (most commonly obtained from an Ably Token Request response). This option is mostly useful for testing: since tokens are short-lived, in production you almost always want to use an authentication method that allows the client library to renew the token automatically when the previous one expires, such as `authUrl` or `authCallback`. Use this option if you wish to use Token authentication. Read more about [Token authentication](https://ably.com/docs/auth/token)
**Type:** `TokenDetails` |
| tls | A boolean value, indicating whether or not a TLS ("SSL") secure connection should be used. An insecure connection cannot be used with Basic authentication as it would lead to a possible compromise of the private API key while in transit. [Find out more about TLS](https://faqs.ably.com/are-messages-sent-to-and-received-from-ably-securely-using-tls)
**Type:** `Boolean`
**Default:** true |
| clientId | A client ID, used for identifying this client when publishing messages or for presence purposes. The `clientId` can be any non-empty string. This option is primarily intended to be used in situations where the library is instantiated with a key; note that a `clientId` may also be implicit in a token used to instantiate the library; an error will be raised if a `clientId` specified here conflicts with the `clientId` implicit in the token. [Find out more about client identities](https://ably.com/docs/auth/identified-clients)
**Type:** `String` |
| useTokenAuth | When true, forces [Token authentication](https://ably.com/docs/auth/token) to be used by the library. Please note that if a `clientId` is not specified in the [`ClientOptions`](https://ably.com/docs/api/realtime-sdk/types#client-options) or [`TokenParams`](https://ably.com/docs/api/realtime-sdk/types#token-params), then the Ably Token issued will be [anonymous](https://faqs.ably.com/authenticated-and-identified-clients)
**Type:** `Boolean`
**Default:** false |
| endpoint | Enables [enterprise customers](https://ably.com/pricing) to use their own custom endpoints, which support dedicated, isolated clusters and regional message routing and storage constraints. See our [platform customization guide](https://ably.com/docs/platform/account/enterprise-customization) for more details
**Type:** `String`
**Default:** null |
| environment | Deprecated, use `endpoint`. Enables [enterprise customers](https://ably.com/pricing) to use their own custom environments, which support dedicated, isolated clusters and regional message routing and storage constraints. See our [platform customization guide](https://ably.com/docs/platform/account/enterprise-customization) for more details
**Type:** `String`
**Default:** null |
| idempotentRestPublishing | When true, enables idempotent publishing by assigning a unique message ID client-side, allowing the Ably servers to discard automatic publish retries following a failure such as a network fault. We recommend you enable this by default. In version 1.2 onwards, idempotent publishing for retries will be enabled by default
**Type:** `Boolean`
**Default:** false |
| fallbackHosts | An array of fallback hosts to be used in the case of an error necessitating the use of an alternative host. When a custom environment is specified, the [fallback host functionality](https://faqs.ably.com/routing-around-network-and-dns-issues) is disabled. If your customer success manager has provided you with a set of custom fallback hosts, please specify them here
**Type:** `String[]`
**Default:** `[a.ably-realtime.com, b.ably-realtime.com, c.ably-realtime.com, d.ably-realtime.com, e.ably-realtime.com]` |
| transportParams | Optional. Can be used to pass in arbitrary connection parameters, such as [`heartbeatInterval`](https://ably.com/docs/connect#heartbeats) and [`remainPresentFor`](https://ably.com/docs/presence-occupancy/presence#unstable-connections)
**Type:** `Object` |
| useBinaryProtocol | If set to true, will enable the binary protocol (MessagePack) if it is supported. It's disabled by default on browsers for performance considerations (browsers are optimized for decoding JSON)If set to false, will forcibly disable the binary protocol (MessagePack). The binary protocol is used by default unless it is not supported. Find out more about the [benefits of binary encoding](https://faqs.ably.com/do-you-binary-encode-your-messages-for-greater-efficiency)
**Type:** `Boolean`
**Default:** falsetrue |
| queueMessages | If false, this disables the default behavior whereby the library queues messages on a connection in the disconnected or connecting states. The default behavior allows applications to submit messages immediately upon instancing the library without having to wait for the connection to be established. Applications may use this option to disable queueing if they wish to have application-level control over the queueing under those conditions
**Type:** `Boolean`
**Default:** true |
| echoMessages | If false, prevents messages originating from this connection being echoed back on the same connection
**Type:** `Boolean`
**Default:** true |
| autoConnect | By default as soon as the client library is instantiated it will connect to Ably. You can optionally set this to false and explicitly connect to Ably when require using the [`connect`](https://ably.com/docs/api/realtime-sdk/connection#connect) method
**Type:** `Boolean`
**Default:** true |
| logLevel | A number controlling the verbosity of the log output of the library. Valid values are: 0 (no logs), 1 (errors only), 2 (errors plus connection and channel state changes), 3 (high-level debug output), and 4 (full debug output)
**Type:** `Integer` |
| logHandler | A function to handle each line of the library's log output. If `logHandler` is not specified, `console.log` is used
**Type:** `Callable` |
| transports | An optional array of transports to use, in descending order of preference. In the browser environment the available transports are: `web_socket`, `xhr_polling`The transports available in the Node.js client library are: `web_socket`, `xhr_polling`, `comet`
**Type:** `String[]` |
| recover | This option allows a connection to inherit the state of a previous connection that may have existed under a different instance of the Realtime library. This might typically be used by clients of the browser library to ensure connection state can be preserved when the user refreshes the page. A recovery key string can be explicitly provided, or alternatively if a callback function is provided, the client library will automatically persist the recovery key between page reloads and call the callback when the connection is recoverable. The callback is then responsible for confirming whether the connection should be recovered or not. See [connection state recovery](https://ably.com/docs/connect/states) for further information
**Type:** `String`, `Callable`This option allows a connection to inherit the state of a previous connection that may have existed under a different instance of the library by providing that connection's [`recoveryKey`](https://ably.com/docs/api/realtime-sdk/connection#recovery-key). This might typically be used by clients of an app to ensure connection state can be preserved following a reload. See [connection state recovery](https://ably.com/docs/connect/states) for further information and example code
**Type:** `String` |
| closeOnUnload | When true, the client library will automatically send a close request to Ably whenever the `window beforeunload` event fires. By enabling this option, the close request sent to Ably ensures the connection state will not be retained and all channels associated with the connection will be detached. This is commonly used by developers who want presence leave events to fire immediately i.e. if a user navigates to another page or closes their browser, then enabling this option will result in the presence member leaving immediately. Without this option or an explicit call to the [`close`](https://ably.com/docs/api/realtime-sdk/connection#close) method of the [`Connection object`](https://ably.com/docs/api/realtime-sdk/connection), Ably expects that the abruptly disconnected connection could later be recovered and therefore does not immediately remove the user from presence. Instead, to avoid "twitchy" presence behavior an abruptly disconnected client is removed from channels in which they are present after 15 seconds, and the connection state is retained for two minutes
**Type:** `Boolean`
**Default:** true |
| queryTime | If true, the library will query the Ably servers for the current time when [issuing TokenRequests](https://ably.com/docs/auth/token) instead of relying on a locally-available time of day. Knowing the time accurately is needed to create valid signed Ably [TokenRequests](https://ably.com/docs/api/realtime-sdk/authentication#request-token), so this option is useful for library instances on auth servers where for some reason the server clock cannot be kept synchronized through normal means, such as an [NTP daemon](https://en.wikipedia.org/wiki/Ntpd). The server is queried for the current time once per client library instance (which stores the offset from the local clock), so if using this option you should avoid instancing a new version of the library for each request
**Type:** `Boolean`
**Default:** false |
| defaultTokenParams | When a [TokenParams](https://ably.com/docs/api/realtime-sdk/types#token-params) object is provided, it will override the client library defaults when issuing new Ably Tokens or Ably TokenRequests
**Type:** [`TokenParams`](https://ably.com/docs/api/realtime-sdk/types#token-params) |
| disconnectedRetryTimeout | 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
**Type:** `Integer`
**Default:** 15,000ms |
| suspendedRetryTimeout | 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
**Type:** `Integer`
**Default:** 30,000ms |
| pushServiceWorkerUrl | A URL pointing to a service worker script which is used as the target for web push notifications
**Type:** `String` |
| Property | Description |
|----------|-------------|
| Key | The full key string, as obtained from the [application dashboard](https://ably.com/dashboard). Use this option if you wish to use Basic authentication, or wish to be able to issue Ably Tokens without needing to defer to a separate entity to sign Ably TokenRequests. Read more about [Basic authentication](https://ably.com/docs/auth/basic)
**Type:** `String` |
| Token | An authenticated [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) object, a [`TokenRequest`](https://ably.com/docs/api/realtime-sdk/types#token-request) object, or token string (obtained from the `Token` property of a [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) component of an Ably TokenRequest response, or a [JSON Web Token](https://tools.ietf.org/html/rfc7519) satisfying [the Ably requirements for JWTs](https://ably.com/docs/auth/token#jwt)). This option is mostly useful for testing: since tokens are short-lived, in production you almost always want to use an authentication method that allows the client library to renew the token automatically when the previous one expires, such as `AuthUrl` or `AuthCallback`. Read more about [Token authentication](https://ably.com/docs/auth/token)
**Type:** `String`, `TokenDetails` or `TokenRequest` |
| AuthCallback | A function which is called when a new token is required. The role of the callback is to obtain a fresh token, one of: an Ably Token string (in plain text format); a signed [`TokenRequest`](https://ably.com/docs/api/realtime-sdk/types#token-request); a [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) (in JSON format); an [Ably JWT](https://ably.com/docs/api/realtime-sdk/authentication#ably-jwt). See [our authentication documentation](https://ably.com/docs/auth) for details of the Ably TokenRequest format and associated API calls
**Type:** `Func>` |
| AuthUrl | A URL that the library may use to obtain a fresh token, one of: an Ably Token string (in plain text format); a signed [`TokenRequest`](https://ably.com/docs/api/realtime-sdk/types#token-request); a [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) (in JSON format); an [Ably JWT](https://ably.com/docs/api/realtime-sdk/authentication#ably-jwt). For example, this can be used by a client to obtain signed Ably TokenRequests from an application server
**Type:** `Uri` |
| AuthMethod | The HTTP verb to use for the request, either `GET` or `POST`
**Type:** `HttpMethod`
**Default:** `GET` |
| AuthHeaders | A set of key value pair headers to be added to any request made to the `AuthUrl`. Useful when an application requires these to be added to validate the request or implement the response
**Type:** `Dictionary` |
| AuthParams | A set of key value pair params to be added to any request made to the `AuthUrl`. When the `AuthMethod` is `GET`, query params are added to the URL, whereas when `AuthMethod` is `POST`, the params are sent as URL encoded form data. Useful when an application require these to be added to validate the request or implement the response
**Type:** `Dictionary` |
| TokenDetails | An authenticated [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) object (most commonly obtained from an Ably Token Request response). This option is mostly useful for testing: since tokens are short-lived, in production you almost always want to use an authentication method that allows the client library to renew the token automatically when the previous one expires, such as `AuthUrl` or `AuthCallback`. Use this option if you wish to use Token authentication. Read more about [Token authentication](https://ably.com/docs/auth/token)
**Type:** `TokenDetails` |
| Tls | A boolean value, indicating whether or not a TLS ("SSL") secure connection should be used. An insecure connection cannot be used with Basic authentication as it would lead to a possible compromise of the private API key while in transit. [Find out more about TLS](https://faqs.ably.com/are-messages-sent-to-and-received-from-ably-securely-using-tls)
**Type:** `Boolean`
**Default:** true |
| ClientId | A client ID, used for identifying this client when publishing messages or for presence purposes. The `ClientId` can be any non-empty string. This option is primarily intended to be used in situations where the library is instantiated with a key; note that a `ClientId` may also be implicit in a token used to instantiate the library; an error will be raised if a `ClientId` specified here conflicts with the `ClientId` implicit in the token. [Find out more about client identities](https://ably.com/docs/auth/identified-clients)
**Type:** `String` |
| UseTokenAuth | When true, forces [Token authentication](https://ably.com/docs/auth/token) to be used by the library. Please note that if a `clientId` is not specified in the [`ClientOptions`](https://ably.com/docs/api/realtime-sdk/types#client-options) or [`TokenParams`](https://ably.com/docs/api/realtime-sdk/types#token-params), then the Ably Token issued will be [anonymous](https://faqs.ably.com/authenticated-and-identified-clients)
**Type:** `Boolean`
**Default:** false |
| Endpoint | Enables [enterprise customers](https://ably.com/pricing) to use their own custom endpoints, which support dedicated, isolated clusters and regional message routing and storage constraints. See our [platform customization guide](https://ably.com/docs/platform/account/enterprise-customization) for more details
**Type:** `String`
**Default:** null |
| Environment | Deprecated, use `endpoint`. Enables [enterprise customers](https://ably.com/pricing) to use their own custom environments, which support dedicated, isolated clusters and regional message routing and storage constraints. See our [platform customization guide](https://ably.com/docs/platform/account/enterprise-customization) for more details
**Type:** `String`
**Default:** null |
| IdempotentRestPublishing | When true, enables idempotent publishing by assigning a unique message ID client-side, allowing the Ably servers to discard automatic publish retries following a failure such as a network fault. We recommend you enable this by default. In version 1.2 onwards, idempotent publishing for retries will be enabled by default
**Type:** `Boolean`
**Default:** false |
| FallbackHosts | An array of fallback hosts to be used in the case of an error necessitating the use of an alternative host. When a custom environment is specified, the [fallback host functionality](https://faqs.ably.com/routing-around-network-and-dns-issues) is disabled. If your customer success manager has provided you with a set of custom fallback hosts, please specify them here
**Type:** `String[]`
**Default:** `[a.ably-realtime.com, b.ably-realtime.com, c.ably-realtime.com, d.ably-realtime.com, e.ably-realtime.com]` |
| TransportParams | Optional. Can be used to pass in arbitrary connection parameters, such as [`heartbeatInterval`](https://ably.com/docs/connect#heartbeats) and [`remainPresentFor`](https://ably.com/docs/presence-occupancy/presence#unstable-connections)
**Type:** `Dictionary` |
| LogLevel | This is an enum controlling the verbosity of the output from `Debug` (maximum) to `Error` (errors only). A special value of `None` will silence all logging. Note that the `LogLevel` is a static variable in the library and will thus not act independently between library instances
**Type:** `Enum`
**Default:** `Error` |
| LoggerSink | The default ILoggerSink outputs messages to the debug console. This property allows the user to pipe the log messages to their own logging infrastructure
**Type:** `ILoggerSink`
**Default:** `IO.Ably.DefaultLoggerSink` |
| UseBinaryProtocol | If set to false, will forcibly disable the binary protocol (MessagePack). The binary protocol is used by default unless it is not supported. Find out more about the [benefits of binary encoding](https://faqs.ably.com/do-you-binary-encode-your-messages-for-greater-efficiency)
**Type:** `Boolean`
**Default:** true |
| QueueMessages | If false, this disables the default behavior whereby the library queues messages on a connection in the disconnected or connecting states. The default behavior allows applications to submit messages immediately upon instancing the library without having to wait for the connection to be established. Applications may use this option to disable queueing if they wish to have application-level control over the queueing under those conditions
**Type:** `Boolean`
**Default:** true |
| EchoMessages | If false, prevents messages originating from this connection being echoed back on the same connection
**Type:** `Boolean`
**Default:** true |
| AutoConnect | By default as soon as the client library is instantiated it will connect to Ably. You can optionally set this to false and explicitly connect to Ably when require using the [`connect`](https://ably.com/docs/api/realtime-sdk/connection#connect) method
**Type:** `Boolean`
**Default:** true |
| Recover | This option allows a connection to inherit the state of a previous connection that may have existed under a different instance of the library by providing that connection's [`recoveryKey`](https://ably.com/docs/api/realtime-sdk/connection#recovery-key). This might typically be used by clients of an app to ensure connection state can be preserved following a reload. See [connection state recovery](https://ably.com/docs/connect/states) for further information and example code
**Type:** `String` |
| QueryTime | If true, the library will query the Ably servers for the current time when [issuing TokenRequests](https://ably.com/docs/auth/token) instead of relying on a locally-available time of day. Knowing the time accurately is needed to create valid signed Ably [TokenRequests](https://ably.com/docs/api/realtime-sdk/authentication#request-token), so this option is useful for library instances on auth servers where for some reason the server clock cannot be kept synchronized through normal means, such as an [NTP daemon](https://en.wikipedia.org/wiki/Ntpd). The server is queried for the current time once per client library instance (which stores the offset from the local clock), so if using this option you should avoid instancing a new version of the library for each request
**Type:** `Boolean`
**Default:** false |
| DefaultTokenParams | When a [TokenParams](https://ably.com/docs/api/realtime-sdk/types#token-params) object is provided, it will override the client library defaults when issuing new Ably Tokens or Ably TokenRequests
**Type:** [`TokenParams`](https://ably.com/docs/api/realtime-sdk/types#token-params) |
| DisconnectedRetryTimeout | 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
**Type:** `Integer`
**Default:** 15,000ms |
| SuspendedRetryTimeout | 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
**Type:** `Integer`
**Default:** 30,000ms |
| Property | Description |
|----------|-------------|
| key | The full key string, as obtained from the [application dashboard](https://ably.com/dashboard). Use this option if you wish to use Basic authentication, or wish to be able to issue Ably Tokens without needing to defer to a separate entity to sign Ably TokenRequests. Read more about [Basic authentication](https://ably.com/docs/auth/basic)
**Type:** `String` |
| token | An authenticated [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) object, a [`TokenRequest`](https://ably.com/docs/api/realtime-sdk/types#token-request) object, or token string (obtained from the `token` property of a [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) component of an Ably TokenRequest response, or a [JSON Web Token](https://tools.ietf.org/html/rfc7519) satisfying [the Ably requirements for JWTs](https://ably.com/docs/auth/token#jwt)). This option is mostly useful for testing: since tokens are short-lived, in production you almost always want to use an authentication method that allows the client library to renew the token automatically when the previous one expires, such as `authUrl` or `authCallback`. Read more about [Token authentication](https://ably.com/docs/auth/token)
**Type:** `String`, `TokenDetails` or `TokenRequest` |
| authCallback | A `TokenCallback` instance which is called when a new token is required. The role of the callback is to obtain a fresh token, one of: an Ably Token string (in plain text format); a signed [`TokenRequest`](https://ably.com/docs/api/realtime-sdk/types#token-request); a [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) (in JSON format); an [Ably JWT](https://ably.com/docs/api/realtime-sdk/authentication#ably-jwt). See [our authentication documentation](https://ably.com/docs/auth) for details of the Ably TokenRequest format and associated API calls
**Type:** `TokenCallback` |
| authUrl | A URL that the library may use to obtain a fresh token, one of: an Ably Token string (in plain text format); a signed [`TokenRequest`](https://ably.com/docs/api/realtime-sdk/types#token-request); a [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) (in JSON format); an [Ably JWT](https://ably.com/docs/api/realtime-sdk/authentication#ably-jwt). For example, this can be used by a client to obtain signed Ably TokenRequests from an application server
**Type:** `String` |
| authMethod | The HTTP verb to use for the request, either `GET` or `POST`
**Type:** `String`
**Default:** `GET` |
| authHeaders | A set of key value pair headers to be added to any request made to the `authUrl`. Useful when an application requires these to be added to validate the request or implement the response
**Type:** `Param[]` |
| authParams | A set of key value pair params to be added to any request made to the `authUrl`. When the `authMethod` is `GET`, query params are added to the URL, whereas when `authMethod` is `POST`, the params are sent as URL encoded form data. Useful when an application require these to be added to validate the request or implement the response
**Type:** `Param[]` |
| tokenDetails | An authenticated [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) object (most commonly obtained from an Ably Token Request response). This option is mostly useful for testing: since tokens are short-lived, in production you almost always want to use an authentication method that allows the client library to renew the token automatically when the previous one expires, such as `authUrl` or `authCallback`. Use this option if you wish to use Token authentication. Read more about [Token authentication](https://ably.com/docs/auth/token)
**Type:** `TokenDetails` |
| tls | A boolean value, indicating whether or not a TLS ("SSL") secure connection should be used. An insecure connection cannot be used with Basic authentication as it would lead to a possible compromise of the private API key while in transit. [Find out more about TLS](https://faqs.ably.com/are-messages-sent-to-and-received-from-ably-securely-using-tls)
**Type:** `Boolean`
**Default:** true |
| clientId | A client ID, used for identifying this client when publishing messages or for presence purposes. The `clientId` can be any non-empty string. This option is primarily intended to be used in situations where the library is instantiated with a key; note that a `clientId` may also be implicit in a token used to instantiate the library; an error will be raised if a `clientId` specified here conflicts with the `clientId` implicit in the token. [Find out more about client identities](https://ably.com/docs/auth/identified-clients)
**Type:** `String` |
| useTokenAuth | When true, forces [Token authentication](https://ably.com/docs/auth/token) to be used by the library. Please note that if a `clientId` is not specified in the [`ClientOptions`](https://ably.com/docs/api/realtime-sdk/types#client-options) or [`TokenParams`](https://ably.com/docs/api/realtime-sdk/types#token-params), then the Ably Token issued will be [anonymous](https://faqs.ably.com/authenticated-and-identified-clients)
**Type:** `Boolean`
**Default:** false |
| endpoint | Enables [enterprise customers](https://ably.com/pricing) to use their own custom endpoints, which support dedicated, isolated clusters and regional message routing and storage constraints. See our [platform customization guide](https://ably.com/docs/platform/account/enterprise-customization) for more details
**Type:** `String`
**Default:** Null |
| environment | Deprecated, use `endpoint`. Enables [enterprise customers](https://ably.com/pricing) to use their own custom environments, which support dedicated, isolated clusters and regional message routing and storage constraints. See our [platform customization guide](https://ably.com/docs/platform/account/enterprise-customization) for more details
**Type:** `String`
**Default:** Null |
| idempotentRestPublishing | When true, enables idempotent publishing by assigning a unique message ID client-side, allowing the Ably servers to discard automatic publish retries following a failure such as a network fault. We recommend you enable this by default. In version 1.2 onwards, idempotent publishing for retries will be enabled by default
**Type:** `Boolean`
**Default:** false |
| fallbackHosts | An array of fallback hosts to be used in the case of an error necessitating the use of an alternative host. When a custom environment is specified, the [fallback host functionality](https://faqs.ably.com/routing-around-network-and-dns-issues) is disabled. If your customer success manager has provided you with a set of custom fallback hosts, please specify them here
**Type:** `String[]`
**Default:** `[a.ably-realtime.com, b.ably-realtime.com, c.ably-realtime.com, d.ably-realtime.com, e.ably-realtime.com]` |
| transportParams | Optional. Can be used to pass in arbitrary connection parameters, such as [`heartbeatInterval`](https://ably.com/docs/connect#heartbeats) and [`remainPresentFor`](https://ably.com/docs/presence-occupancy/presence#unstable-connections)
**Type:** `Param[]` |
| logLevel | A number controlling the verbosity of the output from 2 (maximum, verbose) to 6 (errors only). A special value of 99 will silence all logging. Note that the `logLevel` is a static variable in the library and will thus not act independently between library instances when multiple library instances exist concurrently. See [the logging section of the java library README](https://github.com/ably/ably-java/#logging) for more details
**Type:** `Integer`
**Default:** 5 |
| logHandler | A `LogHandler` interface can be specified to handle each line of log output. If `logHandler` is not specified, `System.out` is used. Note that the `logHandler` is a static variable in the library and will thus not act independently between library instances when multiple library instances exist concurrently. See [the logging section of the java library README](https://github.com/ably/ably-java/#logging) for more details
**Type:** `PrintStream`
**Default:** `System.out PrintStream` |
| useBinaryProtocol | If set to false, will forcibly disable the binary protocol (MessagePack). The binary protocol is used by default unless it is not supported. Find out more about the [benefits of binary encoding](https://faqs.ably.com/do-you-binary-encode-your-messages-for-greater-efficiency)
**Type:** `Boolean`
**Default:** true |
| queueMessages | If false, this disables the default behavior whereby the library queues messages on a connection in the disconnected or connecting states. The default behavior allows applications to submit messages immediately upon instancing the library without having to wait for the connection to be established. Applications may use this option to disable queueing if they wish to have application-level control over the queueing under those conditions
**Type:** `Boolean`
**Default:** true |
| echoMessages | If false, prevents messages originating from this connection being echoed back on the same connection
**Type:** `Boolean`
**Default:** true |
| autoConnect | By default as soon as the client library is instantiated it will connect to Ably. You can optionally set this to false and explicitly connect to Ably when require using the [`connect`](https://ably.com/docs/api/realtime-sdk/connection#connect) method
**Type:** `Boolean`
**Default:** true |
| recover | This option allows a connection to inherit the state of a previous connection that may have existed under a different instance of the library by providing that connection's [`recoveryKey`](https://ably.com/docs/api/realtime-sdk/connection#recovery-key). This might typically be used by clients of an app to ensure connection state can be preserved following a reload. See [connection state recovery](https://ably.com/docs/connect/states) for further information and example code
**Type:** `String` |
| queryTime | If true, the library will query the Ably servers for the current time when [issuing TokenRequests](https://ably.com/docs/auth/token) instead of relying on a locally-available time of day. Knowing the time accurately is needed to create valid signed Ably [TokenRequests](https://ably.com/docs/api/realtime-sdk/authentication#request-token), so this option is useful for library instances on auth servers where for some reason the server clock cannot be kept synchronized through normal means, such as an [NTP daemon](https://en.wikipedia.org/wiki/Ntpd). The server is queried for the current time once per client library instance (which stores the offset from the local clock), so if using this option you should avoid instancing a new version of the library for each request
**Type:** `Boolean`
**Default:** false |
| defaultTokenParams | When a [TokenParams](https://ably.com/docs/api/realtime-sdk/types#token-params) object is provided, it will override the client library defaults when issuing new Ably Tokens or Ably TokenRequests
**Type:** [`TokenParams`](https://ably.com/docs/api/realtime-sdk/types#token-params) |
| disconnectedRetryTimeout | 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
**Type:** `Integer`
**Default:** 15,000ms |
| suspendedRetryTimeout | 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
**Type:** `Integer`
**Default:** 30,000ms |
| Property | Description |
|----------|-------------|
| :key | The full key string, as obtained from the [application dashboard](https://ably.com/dashboard). Use this option if you wish to use Basic authentication, or wish to be able to issue Ably Tokens without needing to defer to a separate entity to sign Ably TokenRequests. Read more about [Basic authentication](https://ably.com/docs/auth/basic)
**Type:** `String` |
| :token | An authenticated [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) object, a [`TokenRequest`](https://ably.com/docs/api/realtime-sdk/types#token-request) object, or token string (obtained from the :token property of a [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) component of an Ably TokenRequest response, or a [JSON Web Token](https://tools.ietf.org/html/rfc7519) satisfying [the Ably requirements for JWTs](https://ably.com/docs/auth/token#jwt)). This option is mostly useful for testing: since tokens are short-lived, in production you almost always want to use an authentication method that allows the client library to renew the token automatically when the previous one expires, such as :auth_url or :auth_callback. Read more about [Token authentication](https://ably.com/docs/auth/token)
**Type:** `String`, `TokenDetails` or `TokenRequest` |
| :auth_callback | A proc / lambda (called synchronously in REST and Realtime but does not block EventMachine in the latter) which is called when a new token is required. The role of the callback is to obtain a fresh token, one of: an Ably Token string (in plain text format); a signed [`TokenRequest`](https://ably.com/docs/api/realtime-sdk/types#token-request); a [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) (in JSON format); an [Ably JWT](https://ably.com/docs/api/realtime-sdk/authentication#ably-jwt). See [our authentication documentation](https://ably.com/docs/auth) for details of the Ably TokenRequest format and associated API calls
**Type:** `Proc` |
| :auth_url | A URL that the library may use to obtain a fresh token, one of: an Ably Token string (in plain text format); a signed [`TokenRequest`](https://ably.com/docs/api/realtime-sdk/types#token-request); a [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) (in JSON format); an [Ably JWT](https://ably.com/docs/api/realtime-sdk/authentication#ably-jwt). For example, this can be used by a client to obtain signed Ably TokenRequests from an application server
**Type:** String |
| :auth_method | The HTTP verb to use for the request, either `:get` or `:post`
**Type:** `Symbol`
**Default:** `:get` |
| :auth_headers | A set of key value pair headers to be added to any request made to the :auth_url. Useful when an application requires these to be added to validate the request or implement the response
**Type:** `Hash` |
| :auth_params | A set of key value pair params to be added to any request made to the :auth_url. When the :auth_method is `GET`, query params are added to the URL, whereas when :auth_method is `POST`, the params are sent as URL encoded form data. Useful when an application require these to be added to validate the request or implement the response
**Type:** `Hash` |
| :token_details | An authenticated [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) object (most commonly obtained from an Ably Token Request response). This option is mostly useful for testing: since tokens are short-lived, in production you almost always want to use an authentication method that allows the client library to renew the token automatically when the previous one expires, such as :auth_url or :auth_callback. Use this option if you wish to use Token authentication. Read more about [Token authentication](https://ably.com/docs/auth/token)
**Type:** `TokenDetails` |
| :tls | A boolean value, indicating whether or not a TLS ("SSL") secure connection should be used. An insecure connection cannot be used with Basic authentication as it would lead to a possible compromise of the private API key while in transit. [Find out more about TLS](https://faqs.ably.com/are-messages-sent-to-and-received-from-ably-securely-using-tls)
**Type:** `Boolean`
**Default:** true |
| :client_id | A client ID, used for identifying this client when publishing messages or for presence purposes. The `client_id` can be any non-empty string. This option is primarily intended to be used in situations where the library is instantiated with a key; note that a `client_id` may also be implicit in a token used to instantiate the library; an error will be raised if a `client_id` specified here conflicts with the `client_id` implicit in the token. [Find out more about client identities](https://ably.com/docs/auth/identified-clients)
**Type:** `String` |
| :use_token_auth | When true, forces [Token authentication](https://ably.com/docs/auth/token) to be used by the library. Please note that if a `client_id` is not specified in the [`ClientOptions`](https://ably.com/docs/api/realtime-sdk/types#client-options) or [`TokenParams`](https://ably.com/docs/api/realtime-sdk/types#token-params), then the Ably Token issued will be [anonymous](https://faqs.ably.com/authenticated-and-identified-clients)
**Type:** `Boolean`
**Default:** false |
| :endpoint | Enables [enterprise customers](https://ably.com/pricing) to use their own custom endpoints, which support dedicated, isolated clusters and regional message routing and storage constraints. See our [platform customization guide](https://ably.com/docs/platform/account/enterprise-customization) for more details
**Type:** `String`
**Default:** nil |
| :environment | Deprecated, use `endpoint`. Enables [enterprise customers](https://ably.com/pricing) to use their own custom environments, which support dedicated, isolated clusters and regional message routing and storage constraints. See our [platform customization guide](https://ably.com/docs/platform/account/enterprise-customization) for more details
**Type:** `String`
**Default:** nil |
| :idempotent_rest_publishing | When true, enables idempotent publishing by assigning a unique message ID client-side, allowing the Ably servers to discard automatic publish retries following a failure such as a network fault. We recommend you enable this by default. In version 1.2 onwards, idempotent publishing for retries will be enabled by default
**Type:** `Boolean`
**Default:** false |
| :fallback_hosts | An array of fallback hosts to be used in the case of an error necessitating the use of an alternative host. When a custom environment is specified, the [fallback host functionality](https://faqs.ably.com/routing-around-network-and-dns-issues) is disabled. If your customer success manager has provided you with a set of custom fallback hosts, please specify them here
**Type:** `String[]`
**Default:** `[a.ably-realtime.com, b.ably-realtime.com, c.ably-realtime.com, d.ably-realtime.com, e.ably-realtime.com]` |
| :transport_params | Optional. Can be used to pass in arbitrary connection parameters, such as [`heartbeatInterval`](https://ably.com/docs/connect#heartbeats) and [`remainPresentFor`](https://ably.com/docs/presence-occupancy/presence#unstable-connections)
**Type:** `Hash` |
| :log_level | Log level for the standard Logger that outputs to `STDOUT`. Can be set to `:fatal`, `:error`, `:warn`, `:info`, `:debug` or `:none`. Alternatively a [`Logger` severity constant](http://ruby-doc.org/stdlib-2.2.0/libdoc/logger/rdoc/Logger.html#class-Logger-label-Description) can be specified
**Type:** `Symbol`, [`Logger::SEVERITY`](http://ruby-doc.org/stdlib-2.2.0/libdoc/logger/rdoc/Logger.html#class-Logger-label-Description)
**Default:** `:error` |
| :logger | A [Ruby `Logger`](http://ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html) compatible object to handle each line of log output. If `logger` is not specified, `STDOUT` is used
**Type:** [Ruby `Logger`](http://ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html)
**Default:** `STDOUT Logger` |
| :use_binary_protocol | If set to false, will forcibly disable the binary protocol (MessagePack). The binary protocol is used by default unless it is not supported. Find out more about the [benefits of binary encoding](https://faqs.ably.com/do-you-binary-encode-your-messages-for-greater-efficiency)
**Type:** `Boolean`
**Default:** true |
| :queue_messages | If false, this disables the default behavior whereby the library queues messages on a connection in the disconnected or connecting states. The default behavior allows applications to submit messages immediately upon instancing the library without having to wait for the connection to be established. Applications may use this option to disable queueing if they wish to have application-level control over the queueing under those conditions
**Type:** `Boolean`
**Default:** true |
| :echo_messages | If false, prevents messages originating from this connection being echoed back on the same connection
**Type:** `Boolean`
**Default:** true |
| :auto_connect | By default as soon as the client library is instantiated it will connect to Ably. You can optionally set this to false and explicitly connect to Ably when require using the [`connect`](https://ably.com/docs/api/realtime-sdk/connection#connect) method
**Type:** `Boolean`
**Default:** true |
| :recover | This option allows a connection to inherit the state of a previous connection that may have existed under a different instance of the library by providing that connection's [`recovery_key`](https://ably.com/docs/api/realtime-sdk/connection#recovery-key). This might typically be used by clients of an app to ensure connection state can be preserved following a reload. See [connection state recovery](https://ably.com/docs/connect/states) for further information and example code
**Type:** `String` |
| :query_time | If true, the library will query the Ably servers for the current time when [issuing TokenRequests](https://ably.com/docs/auth/token) instead of relying on a locally-available time of day. Knowing the time accurately is needed to create valid signed Ably [TokenRequests](https://ably.com/docs/api/realtime-sdk/authentication#request-token), so this option is useful for library instances on auth servers where for some reason the server clock cannot be kept synchronized through normal means, such as an [NTP daemon](https://en.wikipedia.org/wiki/Ntpd). The server is queried for the current time once per client library instance (which stores the offset from the local clock), so if using this option you should avoid instancing a new version of the library for each request
**Type:** `Boolean`
**Default:** false |
| :default_token_params | When a [TokenParams](https://ably.com/docs/api/realtime-sdk/types#token-params) object is provided, it will override the client library defaults when issuing new Ably Tokens or Ably TokenRequests
**Type:** [`TokenParams`](https://ably.com/docs/api/realtime-sdk/types#token-params) |
| :disconnected_retry_timeout | When the connection enters the `DISCONNECTED` state, after this delay in seconds, if the state is still `DISCONNECTED`, the client library will attempt to reconnect automatically
**Type:** Integer
**Default:** 15s |
| :suspended_retry_timeout | When the connection enters the `SUSPENDED` state, after this delay in seconds, if the state is still `SUSPENDED`, the client library will attempt to reconnect automatically
**Type:** Integer
**Default:** 30s |
| Property | Description |
|----------|-------------|
| key | The full key string, as obtained from the [application dashboard](https://ably.com/dashboard). Use this option if you wish to use Basic authentication, or wish to be able to issue Ably Tokens without needing to defer to a separate entity to sign Ably TokenRequests. Read more about [Basic authentication](https://ably.com/docs/auth/basic)
**Type:** `String` |
| token | An authenticated [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) object, a [`TokenRequest`](https://ably.com/docs/api/realtime-sdk/types#token-request) object, or token string (obtained from the `token` property of a [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) component of an Ably TokenRequest response, or a [JSON Web Token](https://tools.ietf.org/html/rfc7519) satisfying [the Ably requirements for JWTs](https://ably.com/docs/auth/token#jwt)). This option is mostly useful for testing: since tokens are short-lived, in production you almost always want to use an authentication method that allows the client library to renew the token automatically when the previous one expires, such as `authUrl` or `authCallback`. Read more about [Token authentication](https://ably.com/docs/auth/token)
**Type:** `String`, `TokenDetails` or `TokenRequest` |
| authCallback | A function which is called when a new token is required. The role of the callback is to obtain a fresh token, one of: an Ably Token string (in plain text format); a signed [`TokenRequest`](https://ably.com/docs/api/realtime-sdk/types#token-request); a [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) (in JSON format); an [Ably JWT](https://ably.com/docs/api/realtime-sdk/authentication#ably-jwt). See [our authentication documentation](https://ably.com/docs/auth) for details of the Ably TokenRequest format and associated API calls
**Type:** `Callable` |
| authUrl | A URL that the library may use to obtain a fresh token, one of: an Ably Token string (in plain text format); a signed [`TokenRequest`](https://ably.com/docs/api/realtime-sdk/types#token-request); a [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) (in JSON format); an [Ably JWT](https://ably.com/docs/api/realtime-sdk/authentication#ably-jwt). For example, this can be used by a client to obtain signed Ably TokenRequests from an application server
**Type:** `NSURL` |
| authMethod | The HTTP verb to use for the request, either `GET` or `POST`
**Type:** `String`
**Default:** `GET` |
| authHeaders | A set of key value pair headers to be added to any request made to the `authUrl`. Useful when an application requires these to be added to validate the request or implement the response
**Type:** `Object` |
| authParams | A set of key value pair params to be added to any request made to the `authUrl`. When the `authMethod` is `GET`, query params are added to the URL, whereas when `authMethod` is `POST`, the params are sent as URL encoded form data. Useful when an application require these to be added to validate the request or implement the response
**Type:** `[NSURLQueryItem]/Array` |
| tokenDetails | An authenticated [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) object (most commonly obtained from an Ably Token Request response). This option is mostly useful for testing: since tokens are short-lived, in production you almost always want to use an authentication method that allows the client library to renew the token automatically when the previous one expires, such as `authUrl` or `authCallback`. Use this option if you wish to use Token authentication. Read more about [Token authentication](https://ably.com/docs/auth/token)
**Type:** `TokenDetails` |
| tls | A boolean value, indicating whether or not a TLS ("SSL") secure connection should be used. An insecure connection cannot be used with Basic authentication as it would lead to a possible compromise of the private API key while in transit. [Find out more about TLS](https://faqs.ably.com/are-messages-sent-to-and-received-from-ably-securely-using-tls)
**Type:** `Boolean`
**Default:** true |
| clientId | A client ID, used for identifying this client when publishing messages or for presence purposes. The `clientId` can be any non-empty string. This option is primarily intended to be used in situations where the library is instantiated with a key; note that a `clientId` may also be implicit in a token used to instantiate the library; an error will be raised if a `clientId` specified here conflicts with the `clientId` implicit in the token. [Find out more about client identities](https://ably.com/docs/auth/identified-clients)
**Type:** `String` |
| useTokenAuth | When true, forces [Token authentication](https://ably.com/docs/auth/token) to be used by the library. Please note that if a `clientId` is not specified in the [`ClientOptions`](https://ably.com/docs/api/realtime-sdk/types#client-options) or [`TokenParams`](https://ably.com/docs/api/realtime-sdk/types#token-params), then the Ably Token issued will be [anonymous](https://faqs.ably.com/authenticated-and-identified-clients)
**Type:** `Boolean`
**Default:** false |
| endpoint | Enables [enterprise customers](https://ably.com/pricing) to use their own custom endpoints, which support dedicated, isolated clusters and regional message routing and storage constraints. See our [platform customization guide](https://ably.com/docs/platform/account/enterprise-customization) for more details
**Type:** `String`
**Default:** nil |
| environment | Deprecated, use `endpoint`. Enables [enterprise customers](https://ably.com/pricing) to use their own custom environments, which support dedicated, isolated clusters and regional message routing and storage constraints. See our [platform customization guide](https://ably.com/docs/platform/account/enterprise-customization) for more details
**Type:** `String`
**Default:** nil |
| idempotentRestPublishing | When true, enables idempotent publishing by assigning a unique message ID client-side, allowing the Ably servers to discard automatic publish retries following a failure such as a network fault. We recommend you enable this by default. In version 1.2 onwards, idempotent publishing for retries will be enabled by default
**Type:** `Boolean`
**Default:** false |
| fallbackHosts | An array of fallback hosts to be used in the case of an error necessitating the use of an alternative host. When a custom environment is specified, the [fallback host functionality](https://faqs.ably.com/routing-around-network-and-dns-issues) is disabled. If your customer success manager has provided you with a set of custom fallback hosts, please specify them here
**Type:** `String[]`
**Default:** `[a.ably-realtime.com, b.ably-realtime.com, c.ably-realtime.com, d.ably-realtime.com, e.ably-realtime.com]` |
| transportParams | Optional. Can be used to pass in arbitrary connection parameters, such as [`heartbeatInterval`](https://ably.com/docs/connect#heartbeats) and [`remainPresentFor`](https://ably.com/docs/presence-occupancy/presence#unstable-connections)
**Type:** `Object` |
| logLevel | An enum controlling the verbosity of the output from `ARTLogLevelVerbose` to `ARTLogLevelNone`. A special value of 99 will silence all logging
**Type:** `ARTLogLevel`
**Default:** `ARTLogLevelWarn` |
| logHandler | A `ARTLog` object can be specified to handle each line of log output. If `logHandler` is not specified, a default `ARTLog` instance is used
**Type:** `ARTLog *` |
| useBinaryProtocol | Note: The binary protocol is currently not supported in Swift. Find out more about the [benefits of binary encoding](https://faqs.ably.com/do-you-binary-encode-your-messages-for-greater-efficiency)
**Type:** `Boolean`
**Default:** true |
| logExceptionReportingUrl | Defaults to a string value for an Ably error reporting Data Source Name
**Type:** `String` |
| queueMessages | If false, this disables the default behavior whereby the library queues messages on a connection in the disconnected or connecting states. The default behavior allows applications to submit messages immediately upon instancing the library without having to wait for the connection to be established. Applications may use this option to disable queueing if they wish to have application-level control over the queueing under those conditions
**Type:** `Boolean`
**Default:** true |
| echoMessages | If false, prevents messages originating from this connection being echoed back on the same connection
**Type:** `Boolean`
**Default:** true |
| autoConnect | By default as soon as the client library is instantiated it will connect to Ably. You can optionally set this to false and explicitly connect to Ably when require using the [`connect`](https://ably.com/docs/api/realtime-sdk/connection#connect) method
**Type:** `Boolean`
**Default:** true |
| recover | This option allows a connection to inherit the state of a previous connection that may have existed under a different instance of the library by providing that connection's [`recoveryKey`](https://ably.com/docs/api/realtime-sdk/connection#recovery-key). This might typically be used by clients of an app to ensure connection state can be preserved following a reload. See [connection state recovery](https://ably.com/docs/connect/states) for further information and example code
**Type:** `String` |
| queryTime | If true, the library will query the Ably servers for the current time when [issuing TokenRequests](https://ably.com/docs/auth/token) instead of relying on a locally-available time of day. Knowing the time accurately is needed to create valid signed Ably [TokenRequests](https://ably.com/docs/api/realtime-sdk/authentication#request-token), so this option is useful for library instances on auth servers where for some reason the server clock cannot be kept synchronized through normal means, such as an [NTP daemon](https://en.wikipedia.org/wiki/Ntpd). The server is queried for the current time once per client library instance (which stores the offset from the local clock), so if using this option you should avoid instancing a new version of the library for each request
**Type:** `Boolean`
**Default:** false |
| defaultTokenParams | When a [TokenParams](https://ably.com/docs/api/realtime-sdk/types#token-params) object is provided, it will override the client library defaults when issuing new Ably Tokens or Ably TokenRequests
**Type:** [`TokenParams`](https://ably.com/docs/api/realtime-sdk/types#token-params) |
| disconnectedRetryTimeout | When the connection enters the `DISCONNECTED` state, after this delay as a `NSTimeInterval`, if the state is still `DISCONNECTED`, the client library will attempt to reconnect automatically
**Type:** `NSTimeInterval`
**Default:** 15,000ms |
| suspendedRetryTimeout | When the connection enters the `SUSPENDED` state, after this delay as a `NSTimeInterval`, if the state is still `SUSPENDED`, the client library will attempt to reconnect automatically
**Type:** `NSTimeInterval`
**Default:** 30,000ms |
| Property | Description |
|----------|-------------|
| key | The full key string, as obtained from the [application dashboard](https://ably.com/dashboard). Use this option if you wish to use Basic authentication, or wish to be able to issue Ably Tokens without needing to defer to a separate entity to sign Ably TokenRequests. Read more about [Basic authentication](https://ably.com/docs/auth/basic)
**Type:** `String` |
| token | An authenticated [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) object, a [`TokenRequest`](https://ably.com/docs/api/realtime-sdk/types#token-request) object, or token string (obtained from the `token` property of a [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) component of an Ably TokenRequest response, or a [JSON Web Token](https://tools.ietf.org/html/rfc7519) satisfying [the Ably requirements for JWTs](https://ably.com/docs/auth/token#jwt)). This option is mostly useful for testing: since tokens are short-lived, in production you almost always want to use an authentication method that allows the client library to renew the token automatically when the previous one expires, such as `authUrl` or `authCallback`. Read more about [Token authentication](https://ably.com/docs/auth/token)
**Type:** `String`, `TokenDetails` or `TokenRequest` |
| authCallback | A function which is called when a new token is required. The role of the callback is to obtain a fresh token, one of: an Ably Token string (in plain text format); a signed [`TokenRequest`](https://ably.com/docs/api/realtime-sdk/types#token-request); a [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) (in JSON format); an [Ably JWT](https://ably.com/docs/api/realtime-sdk/authentication#ably-jwt). See [our authentication documentation](https://ably.com/docs/auth) for details of the Ably TokenRequest format and associated API calls
**Type:** `Callable` |
| authUrl | A URL that the library may use to obtain a fresh token, one of: an Ably Token string (in plain text format); a signed [`TokenRequest`](https://ably.com/docs/api/realtime-sdk/types#token-request); a [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) (in JSON format); an [Ably JWT](https://ably.com/docs/api/realtime-sdk/authentication#ably-jwt). For example, this can be used by a client to obtain signed Ably TokenRequests from an application server
**Type:** `NSURL` |
| authMethod | The HTTP verb to use for the request, either `GET` or `POST`
**Type:** `String`
**Default:** `GET` |
| authHeaders | A set of key value pair headers to be added to any request made to the `authUrl`. Useful when an application requires these to be added to validate the request or implement the response
**Type:** `Object` |
| authParams | A set of key value pair params to be added to any request made to the `authUrl`. When the `authMethod` is `GET`, query params are added to the URL, whereas when `authMethod` is `POST`, the params are sent as URL encoded form data. Useful when an application require these to be added to validate the request or implement the response
**Type:** `NSArray` |
| tokenDetails | An authenticated [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) object (most commonly obtained from an Ably Token Request response). This option is mostly useful for testing: since tokens are short-lived, in production you almost always want to use an authentication method that allows the client library to renew the token automatically when the previous one expires, such as `authUrl` or `authCallback`. Use this option if you wish to use Token authentication. Read more about [Token authentication](https://ably.com/docs/auth/token)
**Type:** `TokenDetails` |
| tls | A boolean value, indicating whether or not a TLS ("SSL") secure connection should be used. An insecure connection cannot be used with Basic authentication as it would lead to a possible compromise of the private API key while in transit. [Find out more about TLS](https://faqs.ably.com/are-messages-sent-to-and-received-from-ably-securely-using-tls)
**Type:** `Boolean`
**Default:** true |
| clientId | A client ID, used for identifying this client when publishing messages or for presence purposes. The `clientId` can be any non-empty string. This option is primarily intended to be used in situations where the library is instantiated with a key; note that a `clientId` may also be implicit in a token used to instantiate the library; an error will be raised if a `clientId` specified here conflicts with the `clientId` implicit in the token. [Find out more about client identities](https://ably.com/docs/auth/identified-clients)
**Type:** `String` |
| useTokenAuth | When true, forces [Token authentication](https://ably.com/docs/auth/token) to be used by the library. Please note that if a `clientId` is not specified in the [`ClientOptions`](https://ably.com/docs/api/realtime-sdk/types#client-options) or [`TokenParams`](https://ably.com/docs/api/realtime-sdk/types#token-params), then the Ably Token issued will be [anonymous](https://faqs.ably.com/authenticated-and-identified-clients)
**Type:** `Boolean`
**Default:** false |
| endpoint | Enables [enterprise customers](https://ably.com/pricing) to use their own custom endpoints, which support dedicated, isolated clusters and regional message routing and storage constraints. See our [platform customization guide](https://ably.com/docs/platform/account/enterprise-customization) for more details
**Type:** `String`
**Default:** nil |
| environment | Deprecated, use `endpoint`. Enables [enterprise customers](https://ably.com/pricing) to use their own custom environments, which support dedicated, isolated clusters and regional message routing and storage constraints. See our [platform customization guide](https://ably.com/docs/platform/account/enterprise-customization) for more details
**Type:** `String`
**Default:** nil |
| idempotentRestPublishing | When true, enables idempotent publishing by assigning a unique message ID client-side, allowing the Ably servers to discard automatic publish retries following a failure such as a network fault. We recommend you enable this by default. In version 1.2 onwards, idempotent publishing for retries will be enabled by default
**Type:** `Boolean`
**Default:** false |
| fallbackHosts | An array of fallback hosts to be used in the case of an error necessitating the use of an alternative host. When a custom environment is specified, the [fallback host functionality](https://faqs.ably.com/routing-around-network-and-dns-issues) is disabled. If your customer success manager has provided you with a set of custom fallback hosts, please specify them here
**Type:** `String[]`
**Default:** `[a.ably-realtime.com, b.ably-realtime.com, c.ably-realtime.com, d.ably-realtime.com, e.ably-realtime.com]` |
| transportParams | Optional. Can be used to pass in arbitrary connection parameters, such as [`heartbeatInterval`](https://ably.com/docs/connect#heartbeats) and [`remainPresentFor`](https://ably.com/docs/presence-occupancy/presence#unstable-connections)
**Type:** `Object` |
| logLevel | An enum controlling the verbosity of the output from `ARTLogLevelVerbose` to `ARTLogLevelNone`. A special value of 99 will silence all logging
**Type:** `ARTLogLevel`
**Default:** `ARTLogLevelWarn` |
| logHandler | A `ARTLog` object can be specified to handle each line of log output. If `logHandler` is not specified, a default `ARTLog` instance is used
**Type:** `ARTLog *` |
| useBinaryProtocol | Note: The binary protocol is currently not supported in Objective-C. Find out more about the [benefits of binary encoding](https://faqs.ably.com/do-you-binary-encode-your-messages-for-greater-efficiency)
**Type:** `Boolean`
**Default:** true |
| logExceptionReportingUrl | Defaults to a string value for an Ably error reporting Data Source Name
**Type:** `String` |
| queueMessages | If false, this disables the default behavior whereby the library queues messages on a connection in the disconnected or connecting states. The default behavior allows applications to submit messages immediately upon instancing the library without having to wait for the connection to be established. Applications may use this option to disable queueing if they wish to have application-level control over the queueing under those conditions
**Type:** `Boolean`
**Default:** true |
| echoMessages | If false, prevents messages originating from this connection being echoed back on the same connection
**Type:** `Boolean`
**Default:** true |
| autoConnect | By default as soon as the client library is instantiated it will connect to Ably. You can optionally set this to false and explicitly connect to Ably when require using the [`connect`](https://ably.com/docs/api/realtime-sdk/connection#connect) method
**Type:** `Boolean`
**Default:** true |
| recover | This option allows a connection to inherit the state of a previous connection that may have existed under a different instance of the library by providing that connection's [`recoveryKey`](https://ably.com/docs/api/realtime-sdk/connection#recovery-key). This might typically be used by clients of an app to ensure connection state can be preserved following a reload. See [connection state recovery](https://ably.com/docs/connect/states) for further information and example code
**Type:** `String` |
| queryTime | If true, the library will query the Ably servers for the current time when [issuing TokenRequests](https://ably.com/docs/auth/token) instead of relying on a locally-available time of day. Knowing the time accurately is needed to create valid signed Ably [TokenRequests](https://ably.com/docs/api/realtime-sdk/authentication#request-token), so this option is useful for library instances on auth servers where for some reason the server clock cannot be kept synchronized through normal means, such as an [NTP daemon](https://en.wikipedia.org/wiki/Ntpd). The server is queried for the current time once per client library instance (which stores the offset from the local clock), so if using this option you should avoid instancing a new version of the library for each request
**Type:** `Boolean`
**Default:** false |
| defaultTokenParams | When a [TokenParams](https://ably.com/docs/api/realtime-sdk/types#token-params) object is provided, it will override the client library defaults when issuing new Ably Tokens or Ably TokenRequests
**Type:** [`TokenParams`](https://ably.com/docs/api/realtime-sdk/types#token-params) |
| disconnectedRetryTimeout | When the connection enters the `DISCONNECTED` state, after this delay as a `NSTimeInterval`, if the state is still `DISCONNECTED`, the client library will attempt to reconnect automatically
**Type:** `NSTimeInterval`
**Default:** 15,000ms |
| suspendedRetryTimeout | When the connection enters the `SUSPENDED` state, after this delay as a `NSTimeInterval`, if the state is still `SUSPENDED`, the client library will attempt to reconnect automatically
**Type:** `NSTimeInterval`
**Default:** 30,000ms |
| Property | Description |
|----------|-------------|
| key | The full key string, as obtained from the [application dashboard](https://ably.com/dashboard). Use this option if you wish to use Basic authentication, or wish to be able to issue Ably Tokens without needing to defer to a separate entity to sign Ably TokenRequests. Read more about [Basic authentication](https://ably.com/docs/auth/basic)
**Type:** `String` |
| token | An authenticated [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) object, a [`TokenRequest`](https://ably.com/docs/api/realtime-sdk/types#token-request) object, or token string (obtained from the `token` property of a [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) component of an Ably TokenRequest response, or a [JSON Web Token](https://tools.ietf.org/html/rfc7519) satisfying [the Ably requirements for JWTs](https://ably.com/docs/auth/token#jwt)). This option is mostly useful for testing: since tokens are short-lived, in production you almost always want to use an authentication method that allows the client library to renew the token automatically when the previous one expires, such as `authUrl` or `authCallback`. Read more about [Token authentication](https://ably.com/docs/auth/token)
**Type:** `String`, `TokenDetails` or `TokenRequest` |
| authCallback | A function which is called when a new token is required. The role of the callback is to obtain a fresh token, one of: an Ably Token string (in plain text format); a signed [`TokenRequest`](https://ably.com/docs/api/realtime-sdk/types#token-request); a [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) (in JSON format); an [Ably JWT](https://ably.com/docs/api/realtime-sdk/authentication#ably-jwt). See [our authentication documentation](https://ably.com/docs/auth) for details of the Ably TokenRequest format and associated API calls
**Type:** `Callable` |
| authUrl | A URL that the library may use to obtain a fresh token, one of: an Ably Token string (in plain text format); a signed [`TokenRequest`](https://ably.com/docs/api/realtime-sdk/types#token-request); a [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) (in JSON format); an [Ably JWT](https://ably.com/docs/api/realtime-sdk/authentication#ably-jwt). For example, this can be used by a client to obtain signed Ably TokenRequests from an application server
**Type:** `String` |
| authMethod | The HTTP verb to use for the request, either `GET` or `POST`
**Type:** `String`
**Default:** `GET` |
| authHeaders | A set of key value pair headers to be added to any request made to the `authUrl`. Useful when an application requires these to be added to validate the request or implement the response
**Type:** `Map` |
| authParams | A set of key value pair params to be added to any request made to the `authUrl`. When the `authMethod` is `GET`, query params are added to the URL, whereas when `authMethod` is `POST`, the params are sent as URL encoded form data. Useful when an application require these to be added to validate the request or implement the response
**Type:** `Map` |
| tokenDetails | An authenticated [`TokenDetails`](https://ably.com/docs/api/realtime-sdk/types#token-details) object (most commonly obtained from an Ably Token Request response). This option is mostly useful for testing: since tokens are short-lived, in production you almost always want to use an authentication method that allows the client library to renew the token automatically when the previous one expires, such as `authUrl` or `authCallback`. Use this option if you wish to use Token authentication. Read more about [Token authentication](https://ably.com/docs/auth/token)
**Type:** `TokenDetails` |
| tls | A boolean value, indicating whether or not a TLS ("SSL") secure connection should be used. An insecure connection cannot be used with Basic authentication as it would lead to a possible compromise of the private API key while in transit. [Find out more about TLS](https://faqs.ably.com/are-messages-sent-to-and-received-from-ably-securely-using-tls)
**Type:** `Boolean`
**Default:** true |
| clientId | A client ID, used for identifying this client when publishing messages or for presence purposes. The `clientId` can be any non-empty string. This option is primarily intended to be used in situations where the library is instantiated with a key; note that a `clientId` may also be implicit in a token used to instantiate the library; an error will be raised if a `clientId` specified here conflicts with the `clientId` implicit in the token. [Find out more about client identities](https://ably.com/docs/auth/identified-clients)
**Type:** `String` |
| useTokenAuth | When true, forces [Token authentication](https://ably.com/docs/auth/token) to be used by the library. Please note that if a `clientId` is not specified in the [`ClientOptions`](https://ably.com/docs/api/realtime-sdk/types#client-options) or [`TokenParams`](https://ably.com/docs/api/realtime-sdk/types#token-params), then the Ably Token issued will be [anonymous](https://faqs.ably.com/authenticated-and-identified-clients)
**Type:** `Boolean`
**Default:** false |
| endpoint | Enables [enterprise customers](https://ably.com/pricing) to use their own custom endpoints, which support dedicated, isolated clusters and regional message routing and storage constraints. See our [platform customization guide](https://ably.com/docs/platform/account/enterprise-customization) for more details
**Type:** `String`
**Default:** null |
| environment | Deprecated, use `endpoint`. Enables [enterprise customers](https://ably.com/pricing) to use their own custom environments, which support dedicated, isolated clusters and regional message routing and storage constraints. See our [platform customization guide](https://ably.com/docs/platform/account/enterprise-customization) for more details
**Type:** `String`
**Default:** null |
| idempotentRestPublishing | When true, enables idempotent publishing by assigning a unique message ID client-side, allowing the Ably servers to discard automatic publish retries following a failure such as a network fault. We recommend you enable this by default. In version 1.2 onwards, idempotent publishing for retries will be enabled by default
**Type:** `Boolean`
**Default:** false |
| fallbackHosts | An array of fallback hosts to be used in the case of an error necessitating the use of an alternative host. When a custom environment is specified, the [fallback host functionality](https://faqs.ably.com/routing-around-network-and-dns-issues) is disabled. If your customer success manager has provided you with a set of custom fallback hosts, please specify them here
**Type:** `String[]`
**Default:** `[a.ably-realtime.com, b.ably-realtime.com, c.ably-realtime.com, d.ably-realtime.com, e.ably-realtime.com]` |
| transportParams | Optional. Can be used to pass in arbitrary connection parameters, such as [`heartbeatInterval`](https://ably.com/docs/connect#heartbeats) and [`remainPresentFor`](https://ably.com/docs/presence-occupancy/presence#unstable-connections)
**Type:** `Map` |
| useBinaryProtocol | If set to false, will forcibly disable the binary protocol (MessagePack). The binary protocol is used by default unless it is not supported. Find out more about the [benefits of binary encoding](https://faqs.ably.com/do-you-binary-encode-your-messages-for-greater-efficiency)
**Type:** `Boolean`
**Default:** true |
| queueMessages | If false, this disables the default behavior whereby the library queues messages on a connection in the disconnected or connecting states. The default behavior allows applications to submit messages immediately upon instancing the library without having to wait for the connection to be established. Applications may use this option to disable queueing if they wish to have application-level control over the queueing under those conditions
**Type:** `Boolean`
**Default:** true |
| echoMessages | If false, prevents messages originating from this connection being echoed back on the same connection
**Type:** `Boolean`
**Default:** true |
| autoConnect | By default as soon as the client library is instantiated it will connect to Ably. You can optionally set this to false and explicitly connect to Ably when require using the [`connect`](https://ably.com/docs/api/realtime-sdk/connection#connect) method
**Type:** `Boolean`
**Default:** true |
| queryTime | If true, the library will query the Ably servers for the current time when [issuing TokenRequests](https://ably.com/docs/auth/token) instead of relying on a locally-available time of day. Knowing the time accurately is needed to create valid signed Ably [TokenRequests](https://ably.com/docs/api/realtime-sdk/authentication#request-token), so this option is useful for library instances on auth servers where for some reason the server clock cannot be kept synchronized through normal means, such as an [NTP daemon](https://en.wikipedia.org/wiki/Ntpd). The server is queried for the current time once per client library instance (which stores the offset from the local clock), so if using this option you should avoid instancing a new version of the library for each request
**Type:** `Boolean`
**Default:** false |
| defaultTokenParams | When a [TokenParams](https://ably.com/docs/api/realtime-sdk/types#token-params) object is provided, it will override the client library defaults when issuing new Ably Tokens or Ably TokenRequests
**Type:** [`TokenParams`](https://ably.com/docs/api/realtime-sdk/types#token-params) |
| disconnectedRetryTimeout | 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
**Type:** `Integer`
**Default:** 15,000ms |
| suspendedRetryTimeout | 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
**Type:** `Integer`
**Default:** 30,000ms |
### ARTStatsio.ably.lib.types.StatsAbly::Models::StatsIO.Ably.StatsStats object
A `Stats` object represents an application's statistics for the specified interval and time period. Ably aggregates statistics globally for all accounts and applications, and makes these available both through our [statistics API](https://ably.com/docs/metadata-stats/stats) as well as your [application dashboard](https://ably.com/dashboard).
#### PropertiesMembersAttributes
| Property | Description | Type |
|----------|-------------|------|
| unit | The length of the interval that this statistic covers, such as `'minute'`, `'hour'`, `'day'`, `'month'` | `String` |
| intervalId | The UTC time at which the time period covered by this `Stats` object starts. For example, an interval ID value of "2018-03-01:10" in a `Stats` object whose `unit` is `day` would indicate that the period covered is "2018-03-01:10 .. 2018-03-01:11". All `Stats` objects, except those whose `unit` is `minute`, have an interval ID with resolution of one hour and the time period covered will always begin and end at a UTC hour boundary. For this reason it is not possible to infer the `unit` by looking at the resolution of the `intervalId`. `Stats` objects covering an individual minute will have an interval ID indicating that time; for example "2018-03-01:10:02" | `String` |
| interval_time | A `Date` object representing the parsed `intervalId` (the UTC time at which the time period covered by this `Stats` object starts) | `Date` |
| all | Aggregate count of both `inbound` and `outbound` message stats | [`MessageTypes`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/MessageTypes) |
| apiRequests | Breakdown of API requests received via the Ably REST API | [`RequestCount`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/RequestCount) |
| channels | Breakdown of channel related stats such as min, mean and peak channels | [`ResourceCount`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/ResourceCount) |
| connections | Breakdown of connection related stats such as min, mean and peak connections for TLS and non-TLS connections | [`ConnectionTypes`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/ConnectionTypes) |
| inbound | Statistics such as count and data for all inbound messages received over REST and Realtime connections, organized into normal channel messages or presence messages | [`MessageTraffic`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/MessageTraffic) |
| outbound | Statistics such as count and data for all outbound messages retrieved via REST history requests, received over Realtime connections, or pushed with Webhooks, organized into normal channel messages or presence messages | [`MessageTraffic`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/MessageTraffic) |
| persisted | Messages persisted and later retrieved via the [history API](https://ably.com/docs/storage-history/history) | [`MessageTypes`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/MessageTypes) |
| tokenRequests | Breakdown of Ably Token requests received via the Ably REST API | [`RequestCount`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/RequestCount) |
| push | Detailed stats on push notifications, see [our Push documentation](https://ably.com/push) for more details | `PushStats` |
| Property | Description | Type |
|----------|-------------|------|
| unit | The length of the interval that this statistic covers, such as `'minute'`, `'hour'`, `'day'`, `'month'` | `String` |
| intervalId | The UTC time at which the time period covered by this `Stats` object starts. For example, an interval ID value of "2018-03-01:10" in a `Stats` object whose `unit` is `day` would indicate that the period covered is "2018-03-01:10 .. 2018-03-01:11". All `Stats` objects, except those whose `unit` is `minute`, have an interval ID with resolution of one hour and the time period covered will always begin and end at a UTC hour boundary. For this reason it is not possible to infer the `unit` by looking at the resolution of the `intervalId`. `Stats` objects covering an individual minute will have an interval ID indicating that time; for example "2018-03-01:10:02" | `String` |
| interval_time | A `Date` object representing the parsed `intervalId` (the UTC time at which the time period covered by this `Stats` object starts) | `Date` |
| all | Aggregate count of both `inbound` and `outbound` message stats | [`MessageTypes`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/MessageTypes) |
| apiRequests | Breakdown of API requests received via the Ably REST API | [`RequestCount`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/RequestCount) |
| channels | Breakdown of channel related stats such as min, mean and peak channels | [`ResourceCount`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/ResourceCount) |
| connections | Breakdown of connection related stats such as min, mean and peak connections for TLS and non-TLS connections | [`ConnectionTypes`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/ConnectionTypes) |
| inbound | Statistics such as count and data for all inbound messages received over REST and Realtime connections, organized into normal channel messages or presence messages | [`MessageTraffic`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/MessageTraffic) |
| outbound | Statistics such as count and data for all outbound messages retrieved via REST history requests, received over Realtime connections, or pushed with Webhooks, organized into normal channel messages or presence messages | [`MessageTraffic`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/MessageTraffic) |
| persisted | Messages persisted and later retrieved via the [history API](https://ably.com/docs/storage-history/history) | [`MessageTypes`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/MessageTypes) |
| tokenRequests | Breakdown of Ably Token requests received via the Ably REST API | [`RequestCount`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/RequestCount) |
| push | Detailed stats on push notifications, see [our Push documentation](https://ably.com/push) for more details | `PushStats` |
| Property | Description | Type |
|----------|-------------|------|
| unit | The length of the interval that this statistic covers, such as `'minute'`, `'hour'`, `'day'`, `'month'` | `ARTStatsGranularity` |
| intervalGranularity | Deprecated alias for `unit`; scheduled to be removed in version 2.x client library versions | `ARTStatsGranularity` |
| intervalId | The UTC time at which the time period covered by this `Stats` object starts. For example, an interval ID value of "2018-03-01:10" in a `Stats` object whose `unit` is `day` would indicate that the period covered is "2018-03-01:10 .. 2018-03-01:11". All `Stats` objects, except those whose `unit` is `minute`, have an interval ID with resolution of one hour and the time period covered will always begin and end at a UTC hour boundary. For this reason it is not possible to infer the `unit` by looking at the resolution of the `intervalId`. `Stats` objects covering an individual minute will have an interval ID indicating that time; for example "2018-03-01:10:02" | `String` |
| all | Aggregate count of both `inbound` and `outbound` message stats | [`MessageTypes`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/MessageTypes) |
| apiRequests | Breakdown of API requests received via the Ably REST API | [`RequestCount`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/RequestCount) |
| channels | Breakdown of channel related stats such as min, mean and peak channels | [`ResourceCount`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/ResourceCount) |
| connections | Breakdown of connection related stats such as min, mean and peak connections for TLS and non-TLS connections | [`ConnectionTypes`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/ConnectionTypes) |
| inbound | Statistics such as count and data for all inbound messages received over REST and Realtime connections, organized into normal channel messages or presence messages | [`MessageTraffic`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/MessageTraffic) |
| outbound | Statistics such as count and data for all outbound messages retrieved via REST history requests, received over Realtime connections, or pushed with Webhooks, organized into normal channel messages or presence messages | [`MessageTraffic`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/MessageTraffic) |
| persisted | Messages persisted and later retrieved via the [history API](https://ably.com/docs/storage-history/history) | [`MessageTypes`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/MessageTypes) |
| tokenRequests | Breakdown of Ably Token requests received via the Ably REST API | [`RequestCount`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/RequestCount) |
| push | Detailed stats on push notifications, see [our Push documentation](https://ably.com/push) for more details | `PushStats` |
| Property | Description | Type |
|----------|-------------|------|
| unitUnit | The length of the interval that this statistic covers, such as `:minute`, `:hour`, `:day`, `:month``Minute`, `Hour`, `Day`, `Month``'minute'`, `'hour'`, `'day'`, `'month'` | [`Stats::GRANULARITY`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats#GRANULARITY-constant)[`StatsIntervalGranularity`](https://ably.com/docs/api/realtime-sdk/types#stats-granularity) enum`ARTStatsGranularity` |
| interval_granularityintervalGranularityIntervalGranularity | Deprecated alias for `unit`; scheduled to be removed in version 2.x client library versions | [`Stats::GRANULARITY`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats#GRANULARITY-constant)[`StatsIntervalGranularity`](https://ably.com/docs/api/realtime-sdk/types#stats-granularity) enum`ARTStatsGranularity` |
| intervalIdinterval_idIntervalId | The UTC time at which the time period covered by this `Stats` object starts. For example, an interval ID value of "2018-03-01:10" in a `Stats` object whose `unit` is `day` would indicate that the period covered is "2018-03-01:10 .. 2018-03-01:11". All `Stats` objects, except those whose `unit` is `minute`, have an interval ID with resolution of one hour and the time period covered will always begin and end at a UTC hour boundary. For this reason it is not possible to infer the `unit` by looking at the resolution of the `intervalId`. `Stats` objects covering an individual minute will have an interval ID indicating that time; for example "2018-03-01:10:02" | `String` |
| interval_timeIntervalTime | A `Time``DateTimeOffset``Date` object representing the parsed `intervalId``interval_id``IntervalId` (the UTC time at which the time period covered by this `Stats` object starts) | `Time``DateTimeOffset``Date` |
| allAll | Aggregate count of both `inbound` and `outbound` message stats | [`MessageTypes`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/MessageTypes) |
| apiRequestsapi_requestsApiRequests | Breakdown of API requests received via the Ably REST API | [`RequestCount`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/RequestCount) |
| channelsChannels | Breakdown of channel related stats such as min, mean and peak channels | [`ResourceCount`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/ResourceCount) |
| connectionsConnections | Breakdown of connection related stats such as min, mean and peak connections for TLS and non-TLS connections | [`ConnectionTypes`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/ConnectionTypes) |
| inboundInbound | Statistics such as count and data for all inbound messages received over REST and Realtime connections, organized into normal channel messages or presence messages | [`MessageTraffic`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/MessageTraffic) |
| outboundOutbound | Statistics such as count and data for all outbound messages retrieved via REST history requests, received over Realtime connections, or pushed with Webhooks, organized into normal channel messages or presence messages | [`MessageTraffic`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/MessageTraffic) |
| persistedPersisted | Messages persisted and later retrieved via the [history API](https://ably.com/docs/storage-history/history) | [`MessageTypes`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/MessageTypes) |
| tokenRequeststoken_requestsTokenRequests | Breakdown of Ably Token requests received via the Ably REST API | [`RequestCount`](https://www.rubydoc.info/gems/ably/Ably/Models/Stats/RequestCount) |
| pushPush | Detailed stats on push notifications, see [our Push documentation](https://ably.com/push) for more details | `PushStats` |
| Property | Description | Type |
|----------|-------------|------|
| appId | The ID of the Ably application the statistics relate to | `String` |
| entries | The statistics for the requested time interval and time period. The `schema` property provides further information | `Partial>` |
| inProgress | Optional. For entries that are still in progress, such as the current month, the last sub-interval included in the stats entry. In the format `yyyy-mm-dd:hh:mm:ss` | `String` |
| intervalId | The UTC time period that the stats coverage begins at. If `unit` was requested as `minute` this will be in the format `YYYY-mm-dd:HH:MM`, if `hour` it will be `YYYY-mm-dd:HH`, if `day` it will be `YYYY-mm-dd:00` and if `month` it will be `YYYY-mm-01:00` | `String` |
| schema | The URL of a JSON schema describing the structure of the `Stats` object | `String` |
### ARTStatsGranularityStatsIntervalGranularity
`StatsIntervalGranularity` is an enum specifying the granularity of a [`Stats interval`](https://ably.com/docs/api/rest-sdk/statistics#stats-type).
```javascript
const StatsIntervalGranularity = [
'minute',
'hour',
'day',
'month'
]
```
```nodejs
const StatsIntervalGranularity = [
'minute',
'hour',
'day',
'month'
]
```
`ARTStatsGranularity` is an enum specifying the granularity of a [`ARTStats interval`](https://ably.com/docs/api/rest-sdk/statistics#stats-type).
```objc
typedef NS_ENUM(NSUInteger, ARTStatsGranularity) {
ARTStatsGranularityMinute,
ARTStatsGranularityHour,
ARTStatsGranularityDay,
ARTStatsGranularityMonth
};
```
```swift
enum ARTStatsGranularity : UInt {
case Minute
case Hour
case Day
case Month
}
```
`StatsIntervalGranularity` is an enum specifying the granularity of a [`Stats interval`](https://ably.com/docs/api/rest-sdk/statistics#stats-type).
```csharp
public enum StatsIntervalGranularity
{
Minute,
Hour,
Day,
Month
}
```
### HttpPaginatedResponse
An `HttpPaginatedResponse` is a superset of [`PaginatedResult`](https://ably.com/docs/api/rest-sdk/types#paginated-result), which is a type that represents a page of results plus metadata indicating the relative queries available to it. `HttpPaginatedResponse` additionally carries information about the response to an HTTP request. It is used when [making custom HTTP requests](https://ably.com/docs/api/rest-sdk#request).
#### PropertiesMembersAttributes
| Property | Description | Type |
|----------|-------------|------|
| statusCode | The HTTP status code of the response | `Number` |
| success | Whether the HTTP status code indicates success. This is equivalent to `200 <= statusCode < 300` | `Boolean` |
| headers | The headers of the response | `Object` |
| errorCode | The error code if the `X-Ably-Errorcode` HTTP header is sent in the response | `Int` |
| errorMessage | The error message if the `X-Ably-Errormessage` HTTP header is sent in the response | `String` |
| Property | Description | Type |
|----------|-------------|------|
| statusCode | The HTTP status code of the response | `Number` |
| success | Whether the HTTP status code indicates success. This is equivalent to `200 <= statusCode < 300` | `Boolean` |
| headers | The headers of the response | `Object` |
| errorCode | The error code if the `X-Ably-Errorcode` HTTP header is sent in the response | `Int` |
| errorMessage | The error message if the `X-Ably-Errormessage` HTTP header is sent in the response | `String` |
| Property | Description | Type |
|----------|-------------|------|
| statusCode | The HTTP status code of the response | `Number` |
| success | Whether the HTTP status code indicates success. This is equivalent to `200 <= statusCode < 300` | `Boolean` |
| headers | The headers of the response | `Object` |
| errorCode | The error code if the `X-Ably-Errorcode` HTTP header is sent in the response | `Int` |
| errorMessage | The error message if the `X-Ably-Errormessage` HTTP header is sent in the response | `String` |
| Property | Description | Type |
|----------|-------------|------|
| status_code | The HTTP status code of the response | `Number` |
| success | Whether the HTTP status code indicates success. This is equivalent to `200 <= status_code < 300` | `Boolean` |
| headers | The headers of the response | `Object` |
| error_code | The error code if the `X-Ably-Errorcode` HTTP header is sent in the response | `Int` |
| error_message | The error message if the `X-Ably-Errormessage` HTTP header is sent in the response | `String` |
| Property | Description | Type |
|----------|-------------|------|
| statusCode | The HTTP status code of the response | `Number` |
| success | Whether the HTTP status code indicates success. This is equivalent to `200 <= statusCode < 300` | `Boolean` |
| headers | The headers of the response | `Object` |
| errorCode | The error code if the `X-Ably-Errorcode` HTTP header is sent in the response | `Int` |
| errorMessage | The error message if the `X-Ably-Errormessage` HTTP header is sent in the response | `String` |
| Property | Description | Type |
|----------|-------------|------|
| statusCodeStatusCode | The HTTP status code of the response | `Number` |
| successSuccess | Whether the HTTP status code indicates success. This is equivalent to `200 <= statusCode < 300``200 <= StatusCode < 300` | `Boolean` |
| headersHeaders | The headers of the response | `Object` |
| errorCodeErrorCode | The error code if the `X-Ably-Errorcode` HTTP header is sent in the response | `Number``Int` |
| errorMessageErrorMessage | The error message if the `X-Ably-Errormessage` HTTP header is sent in the response | `String` |
#### Methods
##### first
`first(callback(ErrorInfo err, HttpPaginatedResponse resultPage))`
##### first
`first(): Promise`
##### first
`HttpPaginatedResponse first`
##### First
`Task> FirstAsync()`
##### first
`HttpPaginatedResponse first()`
##### first
`first(callback: (ARTHttpPaginatedResponse?, ARTErrorInfo?) -> Void)`
Returns a new `HttpPaginatedResponse` for the first page of results. When using the Realtime library, the `first` method returns a [Deferrable](https://ably.com/docs/api/realtime-sdk/types#deferrable) and yields an [`HttpPaginatedResponse`](https://ably.com/docs/api/realtime-sdk/types#http-paginated-response).The method is asynchronous and returns a Task which needs to be awaited to get the [`HttpPaginatedResponse`](https://ably.com/docs/api/realtime-sdk/types#http-paginated-response).
Returns a promise. On success, the promise is fulfilled with a new `HttpPaginatedResponse` for the first page of results. On failure, the promise is rejected with an [`ErrorInfo`](https://ably.com/docs/api/realtime-sdk/types#error-info) object that details the reason why it was rejected.
##### hasNextHasNexthas_next?
`Boolean hasNext()`
`Boolean has_next?`
`Boolean HasNext()`
`Boolean hasNext()`
`Boolean hasNext()`
Returns `true` if there are more pages available by calling `next``Next` and returns `false` if this page is the last page available.
##### isLastIsLastlast?
`Boolean isLast()`
`Boolean last?`
`Boolean IsLast()`
`Boolean isLast()`
`Boolean isLast()`
Returns `true` if this page is the last page and returns `false` if there are more pages available by calling `next``Next` available.
##### nextNext
`next(callback(ErrorInfo err, HttpPaginatedResponse resultPage))`
`next(): Promise`
`HttpPaginatedResponse next`
`Task> NextAsync()`
`HttpPaginatedResponse next()`
`next(callback: (ARTHttpPaginatedResponse?, ARTErrorInfo?) -> Void)`
Returns a new `HttpPaginatedResponse` loaded with the next page of results. If there are no further pages, then `null`a blank HttpPaginatedResponse will be returned`Null``nil` is returned. The method is asynchronous and return a Task which needs to be awaited to get the `HttpPaginatedResponse`When using the Realtime library, the `first` method returns a [Deferrable](https://ably.com/docs/api/realtime-sdk/types#deferrable) and yields an [HttpPaginatedResponse](https://ably.com/docs/api/realtime-sdk/types#http-paginated-response).
Returns a promise. On success, the promise is fulfilled with a new `HttpPaginatedResponse` loaded with the next page of results. If there are no further pages, then `null` is returned. On failure, the promise is rejected with an [`ErrorInfo`](https://ably.com/docs/api/realtime-sdk/types#error-info) object that details the reason why it was rejected.
##### current
`current(): Promise`
Returns a promise. On success, the promise is fulfilled with a new `HttpPaginatedResponse` loaded with the current page of results. On failure, the promise is rejected with an [`ErrorInfo`](https://ably.com/docs/api/realtime-sdk/types#error-info) object that details the reason why it was rejected.
#### Example
The `HttpPaginatedResponse` interface is a superset of `PaginatedResult`, see the [`PaginatedResult` example](https://ably.com/docs/api/rest-sdk/types/#paginated-result-example)
### io.ably.lib.types.Param
`Param` is a type encapsulating a key/value pair. This type is used frequently in method parameters allowing key/value pairs to be used more flexible, see [`Channel#history`](https://ably.com/docs/api/realtime-sdk/history#channel-history) for an example.
Please note that `key` and `value` attributes are always strings. If an `Integer` or other value type is expected, then you must coerce that type into a `String`.
#### Members
| Property | Description | Type |
|----------|-------------|------|
| key | The key value | `String` |
| value | The value associated with the `key` | `String` |
### BatchPublishSpec
A `BatchPublishSpec` describes the messages that should be published by a batch publish operation, and the channels to which they should be published.
#### Properties
| Property | Description | Type |
|----------|-------------|------|
| channels | The names of the channels to publish the `messages` to | `String[]` |
| messages | An array of [`Message`](https://ably.com/docs/api/realtime-sdk/types#message) objects | [`Message[]`](/docs/api/realtime-sdk/types#message) |
### BatchResult
A `BatchResult` contains information about the results of a batch operation.
#### Properties
| Property | Description | Type |
|----------|-------------|------|
| successCount | The number of successful operations in the request | `Number` |
| failureCount | The number of unsuccessful operations in the request | `Number` |
| messages | An array of results for the batch operation (for example, an array of [`BatchPublishSuccessResult`](https://ably.com/docs/api/realtime-sdk/types#batch-publish-success-result) or [`BatchPublishFailureResult`](https://ably.com/docs/api/realtime-sdk/types#batch-publish-failure-result) for a channel batch publish request) | `Object[]` |
### BatchPublishSuccessResult
A `BatchPublishSuccessResult` contains information about the result of successful publishes to a channel requested by a single [`BatchPublishSpec`](https://ably.com/docs/api/realtime-sdk/types#batch-publish-spec).
#### Properties
| Property | Description | Type |
|----------|-------------|------|
| channel | The name of the channel the message(s) was published to | `String` |
| messageId | A unique ID prefixed to the `Message.id` of each published message | `String` |
### BatchPublishFailureResult
A `BatchPublishFailureResult` contains information about the result of unsuccessful publishes to a channel requested by a single [`BatchPublishSpec`](https://ably.com/docs/api/realtime-sdk/types#batch-publish-spec).
#### Properties
| Property | Description | Type |
|----------|-------------|------|
| channel | The name of the channel the message(s) failed to be published to | `String` |
| error | Describes the reason for which the message(s) failed to publish to the channel as an [`ErrorInfo`](https://ably.com/docs/api/realtime-sdk/types#error-info) object | [`ErrorInfo`](https://ably.com/docs/api/realtime-sdk/types#error-info) |
### BatchPresenceSuccessResult
A `BatchPresenceSuccessResult` contains information about the result of a successful batch presence request for a single channel.
#### Properties
| Property | Description | Type |
|----------|-------------|------|
| channel | The channel name the presence state was retrieved for | `String` |
| presence | An array of [`PresenceMessage`](https://ably.com/docs/api/realtime-sdk/types#presence-message) describing members present on the channel | [`PresenceMessage[]`](/docs/api/realtime-sdk/types#presence-message) |
### BatchPresenceFailureResult
A `BatchPresenceFailureResult` contains information about the result of an unsuccessful batch presence request for a single channel.
#### Properties
| Property | Description | Type |
|----------|-------------|------|
| channel | The channel name the presence state failed to be retrieved for | `String` |
| error | Describes the reason for which presence state could not be retrieved for the channel as an [`ErrorInfo`](https://ably.com/docs/api/realtime-sdk/types#error-info) object | [`ErrorInfo`](https://ably.com/docs/api/realtime-sdk/types#error-info) |