WebSocket Connection
Connect to Directus via WebSocket for bidirectional communication:WebSocket URL
The WebSocket endpoint is available at:Authentication
Authenticate your WebSocket connection:Using Email & Password
Using Access Token
Using Refresh Token
Subscriptions
Subscribe to real-time updates for collections:Subscribe to Collection
Subscription Events
WebSocket subscriptions emit different event types:- init - Initial data when subscription starts
- create - New items matching the filter
- update - Items updated to match the filter
- delete - Items deleted or no longer match filter
Subscription Message Format
Live Queries
Execute live queries that update automatically:Heartbeat
Maintain connection with heartbeat pings:Connection Management
Connection Events
Disconnect
Reconnection
The SDK automatically attempts to reconnect on connection loss:Collaborative Editing
Directus supports collaborative editing with operational transformation:Presence
Track online users and their activity:Real-Time Notifications
Implement live notification system:Activity Feed
Create real-time activity streams:Live Dashboard
Build real-time dashboards:Performance Considerations
Filter Subscriptions
Always use filters to limit subscription data:Limit Fields
Request only needed fields:Unsubscribe When Done
WebSocket Configuration
Server Configuration
Error Handling
Best Practices
Filter Aggressively
Filter Aggressively
Only subscribe to data you need. Use filters to reduce bandwidth and processing.
Handle Reconnections
Handle Reconnections
Implement UI feedback for connection state and handle reconnection gracefully.
Unsubscribe When Not Needed
Unsubscribe When Not Needed
Clean up subscriptions when components unmount or data is no longer needed.
Use Heartbeats
Use Heartbeats
Enable heartbeats to detect stale connections and reconnect automatically.