WebSocket Documentation
Overview
Complete WebSocket integration guide for RNode Server with automatic optimization and performance monitoring.
Key Features:
- Automatic event optimization based on callback presence
- Room-based messaging system
- Client management and tracking
- Built-in reconnection handling
- Performance monitoring and metrics
Documentation Sections
Getting Started
- Examples - Practical examples and use cases
- API Reference - Complete API documentation
- Client - WebSocket client library
- Architecture - System design and optimization
Quick Start
Basic WebSocket Setup
javascript
import { createApp } from 'rnode-server';
const app = createApp({ logLevel: "debug", metrics: true });
// WebSocket route with optimization
app.websocket('/chat', {
onConnect: (data) => {
console.log('🔌 Client connected:', data);
},
onMessage: (data) => {
console.log('📨 Message received:', data);
},
onClose: (data) => {
console.log('🔌 Client disconnected:', data);
}
});
app.listen(4547, () => {
console.log('🚀 WebSocket Server started on port 4547');
});Optimized Configuration
javascript
// Minimal configuration - only message handling
app.websocket('/notifications', {
onMessage: (data) => {
console.log('📨 Notification received:', data);
}
// No other callbacks - events automatically disabled
// This optimizes performance by reducing backend processing
});Performance Optimization
Automatic Event Filtering
The system automatically optimizes performance by:
- Detecting Callbacks: Only events with defined callbacks are enabled
- Backend Filtering: Rust backend checks enabled events before processing
- Reduced Overhead: Unnecessary events are filtered at the backend level
Features
Room Management
- Create and manage WebSocket rooms
- Send messages to specific rooms
- Track room membership
- Room-based broadcasting
Client Management
- Track client connections
- Monitor client activity
- Manage client rooms
- Client information retrieval
Event Handling
- Connect/disconnect events
- Message processing
- Error handling
- Room join/leave events
- Ping/pong management
Performance Monitoring
- Real-time metrics
- Connection tracking
- Message counting
- Performance logging
Next Steps
- Examples - Start with practical examples
- API Reference - Complete API documentation
- Architecture - Understand system design