Skip to main content

Overview

The Directus SDK provides real-time functionality through WebSocket connections, allowing you to subscribe to live updates for collections, send custom messages, and handle WebSocket events.

Setup

Basic Real-time Client

Create a client with real-time capabilities:

Authentication Modes

The realtime() composable supports three authentication modes:
  • handshake - Authenticate during connection (default, recommended)
  • strict - Pass token in URL query parameter
  • public - No authentication (for public data)

Public Mode

Subscriptions

Subscribe to Collection Updates

Subscribe to real-time updates for a collection:

Subscription Events

Subscriptions emit different event types:
  • init - Initial data when subscription starts
  • create - New item created
  • update - Existing item updated
  • delete - Item deleted

Unsubscribe

Stop listening to updates:

WebSocket Events

Listen to WebSocket Events

Handle low-level WebSocket events:

Send Custom Messages

Send Messages

Send custom messages through the WebSocket:

Ping/Pong Example

Connection Management

Connect

Disconnect

Check Connection Status

Configuration

Advanced Configuration

Custom WebSocket URL

Full Example

Complete example with authentication and subscriptions:

Type Signatures

Next Steps

Items Operations

Perform CRUD operations on items

Authentication

Authenticate for protected subscriptions

WebSocket API

Learn about WebSocket protocol details

Flows

Trigger flows from real-time events