This package is currently in beta. All APIs are subject to change without notice. Breaking changes may occur in any release until version 1.0.0.
@sonicus-sdk/core is a real-time communication SDK that provides WebSocket-based functionality for:
- Presence management
- Channel-based messaging
- Chat functionality with reactions and typing indicators
- Cursor position sharing
- Automatic reconnection handling
- This is a pre-release version
- APIs are unstable and may change
- Breaking changes are expected
- Not recommended for production use
- Use at your own risk
npm install @sonicus-sdk/core@beta
import { SonicusClient } from '@sonicus-sdk/core';
// Define your presence status type
type UserPresence = {
status: 'online' | 'offline' | 'away';
timestamp: string;
};
// Create a WebSocket handler
const wsHandler = {
onMessage: (message) => {
console.log('Received message:', message);
},
onError: (event) => {
console.error('WebSocket error:', event);
},
onClose: (event) => {
console.log('WebSocket closed:', event);
},
onOpen: (event) => {
console.log('WebSocket connected:', event);
},
};
// Initialize the client
const client = new SonicusClient<UserPresence>({
authUrl: '/api/sonicus/jwt/issue',
wsUrl: 'wss://sonicus-platform.fly.dev',
}, wsHandler);
// Initialize the connection
await client.init();
- Track user presence status
- Update presence information
- Monitor group presence
- Join/leave channels
- Send/receive messages
- Broadcast messages to channel members
- Join/leave chat rooms
- Send messages with reactions
- Typing indicators
- Message reactions
- Share cursor positions in real-time
- Track multiple users' cursor positions
- Join/leave cursor sharing groups
interface SonicusConfig {
authUrl?: string; // Default: '/api/sonicus/jwt/issue'
refreshUrl?: string; // Default: '/api/sonicus/jwt/refresh'
authMethod?: 'GET' | 'POST' | 'PUT';
headers?: Record<string, string>;
wsUrl?: string; // Default: 'wss://sonicus-platform.fly.dev'
reconnectInterval?: number; // Default: 5000ms
maxReconnectAttempts?: number; // Default: 5
defaultPresenceStatus?: T; // Custom presence status type
}
The client maintains the following connection states:
-
connecting
: Initial connection attempt -
connected
: Successfully connected -
disconnected
: Not connected -
reconnecting
: Attempting to reconnect after disconnection
Documentation is subject to change. Please refer to the latest version for the most up-to-date information.
While this package is in beta, we welcome feedback and bug reports. Please open an issue if you encounter any problems.
[License information will be added before final release]