Using the Realtime library
The Realtime library when initialized attempts to establish and maintain a single connection to the Ably realtime service. This library extends the REST library to provide all REST API functionality including the authentication API. Whereas the Ably REST API is stateless, the Realtime API maintains connection and channel state.
The Ably Realtime client library is available for most popular languages and platforms with a consistent API across all platforms. You can view this documentation with your preferred language API and code examples using the language selector navigation above. If your preferred language is not listed in the language selector, we recommend you download a library in your preferred language and use this documentation as an API reference.
The Realtime library for browser JavaScript environments should be loaded from the Ably CDN as follows:
<script lang="text/javascript" src="https://cdn.ably.com/lib/ably.min-1.js"></script>
CopyCopied!
You can also obtain the library as an NPM module, or download the source directly from Github
The script and module both contain the Realtime and REST libraries as well as all their dependencies. To instantiate the Realtime library:
var realtime = new Ably.Realtime({ key: apiKey });
CopyCopied!
When including the client library from our CDN, we recommend you lock into major version 1
of the library. According to the semantic versioning scheme we adopt, you will then automatically receive minor and patch updates but you will never receive breaking changes. For example, if you lock into major version 1
of the library by including https://cdn.ably.com/lib/ably.min-1.js
, you will receive all minor updates and patch fixes automatically (i.e 1.*.*
). If you want to lock into minor version 1.0
and receive all patch fixes automatically (i.e. 1.0.*
), then use https://cdn.ably.com/lib/ably.min-1.0.js
. Additionally, the .min
suffix can be dropped if you want the non-minified version for debugging.
The supported client options are described in the API reference.
Tutorials
If you would like to see examples of using the Ably Realtime client library, then we recommend you take a look at our Realtime tutorials.
API Reference
View the Constructor API Reference.