Interface ClientOptions

Passes additional client-specific properties to the REST constructor() or the Realtime constructor().

Hierarchy

Properties

authHeaders?: { [index: string]: string }

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 is set on the XHR request.

Type declaration

  • [index: string]: string
authMethod?: HTTPMethods

The HTTP verb to use for any request made to the authUrl, either GET or POST. The default value is GET.

Default Value

HTTPMethods.GET

authParams?: { [index: string]: string }

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 requires these to be added to validate the request or implement the response.

Type declaration

  • [index: string]: string
authUrl?: string

A URL that the library may use to obtain a token string (in plain text format), or a signed TokenRequest or TokenDetails (in JSON format) from.

autoConnect?: boolean

When true, the client connects to Ably as soon as it is instantiated. You can set this to false and explicitly connect to Ably using the connect() method. The default is true.

Default Value

true

clientId?: string

A client ID, used for identifying this client when publishing messages or for presence purposes. The clientId can be any non-empty string, except it cannot contain a *. 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.

closeOnUnload?: boolean

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 channel will be detached. This is commonly used by developers who want presence leave events to fire immediately (that is, 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 method of the Connection object, 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 behaviour 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. Defaults to true.

connectivityCheckUrl?: string

Override the URL used by the realtime client to check if the internet is available.

In the event of a failure to connect to the primary endpoint, the client will send a GET request to this URL to check if the internet is available. If this request returns a success response the client will attempt to connect to a fallback host.

defaultTokenParams?: TokenParams

When a TokenParams object is provided, it overrides the client library defaults when issuing new Ably Tokens or Ably TokenRequests.

disableConnectivityCheck?: boolean

Disable the check used by the realtime client to check if the internet is available before connecting to a fallback host.

disconnectedRetryTimeout?: number

If the connection is still in the DISCONNECTED state after this delay in milliseconds, the client library will attempt to reconnect automatically. The default is 15 seconds.

Default Value

15s

echoMessages?: boolean

If false, prevents messages originating from this connection being echoed back on the same connection. The default is true.

Default Value

true

environment?: string

Enables a custom environment to be used with the Ably service.

fallbackHosts?: string[]

An array of fallback hosts to be used in the case of an error necessitating the use of an alternative host. If you have been provided a set of custom fallback hosts by Ably, please specify them here.

Default Value

`['a.ably-realtime.com', 'b.ably-realtime.com', 'c.ably-realtime.com', 'd.ably-realtime.com', 'e.ably-realtime.com']``

fallbackHostsUseDefault?: boolean

Deprecated

This property is deprecated and will be removed in a future version. Enables default fallback hosts to be used.

httpMaxRetryCount?: number

The maximum number of fallback hosts to use as a fallback when an HTTP request to the primary host is unreachable or indicates that it is unserviceable. The default value is 3.

Default Value

3

httpMaxRetryDuration?: number

The maximum elapsed time in milliseconds in which fallback host retries for HTTP requests will be attempted. The default is 15 seconds.

Default Value

15s

httpOpenTimeout?: number

Timeout in milliseconds for opening a connection to Ably to initiate an HTTP request. The default is 4 seconds.

Default Value

4s

httpRequestTimeout?: number

Timeout in milliseconds for a client performing a complete HTTP request to Ably, including the connection phase. The default is 10 seconds.

Default Value

10s

idempotentRestPublishing?: boolean

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. The default is true.

Default Value

true

key?: string

The full API key string, as obtained from the Ably 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.

log?: LogInfo

Parameters to control the log output of the library, such as the log handler and log level.

Deprecated

This property is deprecated and will be removed in a future version. Use the logLevel and logHandler client options instead.

logHandler?: ((msg: string) => void)

Type declaration

    • (msg: string): void
    • Controls the log output of the library. This is a function to handle each line of log output. If you do not set this value, then console.log will be used.

      Parameters

      • msg: string

        The log message emitted by the library.

      Returns void

logLevel?: number

Controls the verbosity of the logs output from 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).

maxMessageSize?: number

The maximum message size is an attribute of an Ably account which represents the largest permitted payload size of a single message or set of messages published in a single operation. Publish requests whose payload exceeds this limit are rejected by the server. maxMessageSize enables the client to enforce, or further restrict, the maximum size of a single message or set of messages published via REST. The default value is 65536 (64 KiB). In the case of a realtime connection, the server may indicate the associated maximum message size on connection establishment; this value takes precedence over the client's default maxMessageSize.

Default Value

65536

plugins?: { vcdiff?: any }

A map between a plugin type and a plugin object.

Type declaration

port?: number

Enables a non-default Ably port to be specified. For development environments only. The default value is 80.

Default Value

80

queryTime?: boolean

If true, the library queries the Ably servers for the current time when issuing TokenRequests instead of relying on a locally-available time of day. Knowing the time accurately is needed to create valid signed Ably TokenRequests, 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. 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. The default is false.

Default Value

false

queueMessages?: boolean

If false, this disables the default behavior whereby the library queues messages on a connection in the disconnected or connecting states. The default behavior enables applications to submit messages immediately upon instantiating 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. The default is true.

Default Value

true

realtimeHost?: string

Enables a non-default Ably host to be specified for realtime connections. For development environments only. The default value is realtime.ably.io.

Default Value

"realtime.ably.io"

realtimeRequestTimeout?: number

Timeout for the wait of acknowledgement for operations performed via a realtime connection, before the client library considers a request failed and triggers a failure condition. Operations include establishing a connection with Ably, or sending a HEARTBEAT, CONNECT, ATTACH, DETACH or CLOSE request. It is the equivalent of httpRequestTimeout but for realtime operations, rather than REST. The default is 10 seconds.

Default Value

10s

recover?: string | recoverConnectionCallback

Enables 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 for further information.

restAgentOptions?: { keepAlive?: boolean; maxSockets?: number }

Set of configurable options to set on the HTTP(S) agent used for REST requests.

See the NodeJS docs for descriptions of these options.

Type declaration

restHost?: string

Enables a non-default Ably host to be specified. For development environments only. The default value is rest.ably.io.

Default Value

"rest.ably.io"

suspendedRetryTimeout?: number

When the connection enters the SUSPENDED state, after this delay in milliseconds, if the state is still SUSPENDED, the client library attempts to reconnect automatically. The default is 30 seconds.

Default Value

30s

tls?: boolean

When false, the client will use an insecure connection. The default is true, meaning a TLS connection will be used to connect to Ably.

Default Value

true

tlsPort?: number

Enables a non-default Ably TLS port to be specified. For development environments only. The default value is 443.

Default Value

443

token?: string | TokenDetails

An authenticated token. This can either be a TokenDetails object or token string (obtained from the token property of a TokenDetails component of an Ably TokenRequest response, or a JSON Web Token satisfying the Ably requirements for JWTs). This option is mostly useful for testing: since tokens are short-lived, in production you almost always want to use an authentication method that enables the client library to renew the token automatically when the previous one expires, such as authUrl or authCallback. Read more about Token authentication.

tokenDetails?: TokenDetails

An authenticated TokenDetails 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 enables 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.

transportParams?: { [k: string]: string | number }

A set of key-value pairs that can be used to pass in arbitrary connection parameters, such as heartbeatInterval or remainPresentFor.

Type declaration

  • [k: string]: string | number
transports?: Transport[]

An array of transports to use, in descending order of preference. In the browser environment the available transports are: web_socket, xhr, and jsonp.

useBinaryProtocol?: boolean

When true, the more efficient MsgPack binary encoding is used. When false, JSON text encoding is used. The default is true for Node.js, and false for all other platforms.

Default Value

true for Node.js, false for all other platforms

useTokenAuth?: boolean

When true, forces token authentication to be used by the library. If a clientId is not specified in the ClientOptions or TokenParams, then the Ably Token issued is anonymous.

Methods

  • 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; a TokenDetails (in JSON format); an Ably JWT. See the authentication documentation for details of the Ably TokenRequest format and associated API calls.

    Parameters

    • data: TokenParams

      The parameters that should be used to generate the token.

    • callback: ((error: null | string | Types.ErrorInfo, tokenRequestOrDetails: null | string | TokenDetails | TokenRequest) => void)

      A function which, upon success, the authCallback should call with one of: an Ably Token string (in plain text format); a signed TokenRequest; a TokenDetails (in JSON format); an Ably JWT. Upon failure, the authCallback should call this function with information about the error.

        • (error: null | string | Types.ErrorInfo, tokenRequestOrDetails: null | string | TokenDetails | TokenRequest): void
        • A function which, upon success, the authCallback should call with one of: an Ably Token string (in plain text format); a signed TokenRequest; a TokenDetails (in JSON format); an Ably JWT. Upon failure, the authCallback should call this function with information about the error.

          Parameters

          • error: null | string | Types.ErrorInfo

            Should be null if the auth request completed successfully, or containing details of the error if not.

          • tokenRequestOrDetails: null | string | TokenDetails | TokenRequest

            A valid TokenRequest, TokenDetails or Ably JWT to be used for authentication.

          Returns void

    Returns void

Generated using TypeDoc