Overview
Homarr provides a WebSocket server for real-time updates and subscriptions. The WebSocket API uses tRPC over WebSocket, providing the same type-safe interface as the HTTP API.Connection Details
WebSocket Server:ws://localhost:3001 (default)
Protocol: tRPC WebSocket adapter with SuperJSON serialization
Authentication: Session-based (via cookies) or API key
Architecture
The WebSocket server is a separate process that runs alongside the main Homarr application:- Persistent connections for real-time updates
- Automatic reconnection on disconnect
- Heartbeat/keepalive messages
- Same authentication as HTTP API
- Full tRPC query/mutation/subscription support
Connecting to WebSocket
Browser Client
Node.js Client
Connection Lifecycle
Connection Events
Heartbeat
The server sends ping messages every 30 seconds to keep the connection alive:- Ping interval: 30,000ms
- Pong timeout: 5,000ms
- Connection terminated if pong not received
Automatic Reconnection
The tRPC WebSocket client automatically attempts to reconnect:Authentication
Cookie-Based (Browser)
In browsers, session cookies are automatically sent:Manual Session Token (Node.js)
For server-side connections, include the session token:API Key Authentication
API keys are not directly supported over WebSocket. Use session-based authentication instead.Error Handling
Connection Errors
Subscription Errors
Performance Considerations
Connection Pooling
Reuse WebSocket connections across your application:Subscription Management
Unsubscribe when components unmount:Message Batching
tRPC automatically batches messages when possible to reduce overhead.Debugging
Enable Debug Logging
Monitor Connection State
Server Logs
The WebSocket server logs connection events:React Hooks Integration
Use tRPC React Query hooks with WebSocket subscriptions:Next Steps
WebSocket Events
Learn about available WebSocket events and subscriptions
Widget Subscriptions
Real-time widget data subscriptions
