Ably Pub/Sub Dart SDK
Build any realtime experience using Ably's Pub/Sub Dart SDK. A pure Dart implementation with no platform dependencies.
(Note: at this stage, this implementation does not support push messaging, so continue to use ably-flutter if you need that.)
Ably Pub/Sub provides flexible APIs that deliver features such as pub-sub messaging, message history, presence, and push notifications. Utilizing Ably's realtime messaging platform, applications benefit from its highly performant, reliable, and scalable infrastructure.
Find out more:
Getting started
Everything you need to get started with Ably:
Supported platforms
This is a pure Dart package with no platform-specific dependencies. It runs anywhere Dart runs.
| Platform | Support |
|---|---|
| Dart | >=3.0.0 |
Installation
The Dart SDK is available as a pub.dev package. Add it to your pubspec.yaml:
dependencies:
ably: ^0.1.0
Then run:
dart pub get
Usage
REST
Use the REST client for stateless operations like publishing messages and querying history:
import 'package:ably/ably.dart';
// Create a REST client
final rest = RestClient(options: ClientOptions(key: 'your-ably-api-key'));
// Get a channel
final channel = rest.channels.get('test-channel');
// Publish a message
await channel.publish(name: 'greeting', data: 'hello world');
// Retrieve message history
final history = await channel.history();
for (final message in history.items) {
print('${message.name}: ${message.data}');
}
Realtime
Use the Realtime client for persistent connections with live message delivery:
import 'package:ably/ably.dart';
// Create a Realtime client
final realtime = RealtimeClient(
options: ClientOptions(key: 'your-ably-api-key', clientId: 'me'),
);
// Wait for connection
await realtime.connection.once(ConnectionEvent.connected);
print('Connected to Ably');
// Get a channel and subscribe
final channel = realtime.channels.get('test-channel');
await channel.subscribe(listener: (message) {
print('Received: ${message.data}');
});
// Publish a message
await channel.publish(name: 'greeting', data: 'hello world');
Contribute
Read the CONTRIBUTING.md guidelines to contribute to Ably.
Releases
The CHANGELOG.md contains details of the latest releases for this SDK. You can also view all Ably releases on changelog.ably.com.
Support, feedback, and troubleshooting
For help or technical support, visit Ably's support page or GitHub Issues for community-reported bugs and discussions.
Libraries
- ably
- Ably SDK for Dart.