Overview
The Realtime SDK enables you to:- Establish persistent connections to Ably
- Publish and subscribe to messages in realtime
- Track presence of users on channels
- Automatically handle connection state and recovery
- Subscribe to connection and channel state changes
Getting Started
To use the Realtime SDK, first instantiate a client:Core Concepts
Constructor
The Realtime SDK constructor creates a new client instance and establishes a connection to Ably. You can instantiate the client using an API key string or aClientOptions object for more advanced configuration.
See the full constructor documentation for detailed information.
Authentication
The Realtime SDK supports both Basic and Token authentication:- Basic Authentication: Use your API key directly (recommended for server-side only)
- Token Authentication: Use temporary tokens for enhanced security (recommended for client-side)
Channels
Channels are the primary way to organize and route messages in Ably. Each channel provides:- Message publishing and subscription
- Presence functionality
- History retrieval
- State management
Messages
Messages are the data payloads sent and received on channels. Each message contains:- Optional event name
- Data payload
- Metadata (timestamp, client ID, etc.)
Presence
Presence allows you to track which clients are present on a channel:- Enter and leave presence
- Update presence data
- Subscribe to presence events
- Query current presence set
Key Features
Connection Management
The Realtime SDK automatically manages your connection:- Automatic reconnection on network failures
- Connection state recovery
- Fallback host support
- Heartbeat monitoring
Message Delivery Guarantees
Messages published via the Realtime SDK benefit from:- Guaranteed delivery when connection is established
- Automatic message queueing during disconnection
- Message ordering preservation
Real-time Events
Subscribe to events for:- Connection state changes
- Channel state changes
- Incoming messages
- Presence updates
