@bhoomash/syncraft-client
v0.1.0
Published
Client synchronization runtime and WebSocket client for Syncraft
Maintainers
Readme
@bhoomash/syncraft-client
WebSocket client synchronization runtime for Syncraft with automatic offline queuing and exponential backoff reconnection.
Installation
npm install @bhoomash/syncraft-client @bhoomash/syncraft-core @bhoomash/syncraft-storageFeatures
- ⚡ Local-First Writes: State updates synchronously in the UI immediately without waiting for server ACKs.
- 📴 Offline Operation Queue: Seamlessly queues mutations when disconnected and flushes them in batches upon reconnection.
- 🔁 Exponential Backoff Reconnect: Auto-reconnect with configurable jitter and max delay.
- 🌐 Isomorphic WebSocket Support: Works seamlessly in both modern web browsers and Node.js environments.
Quick Start
import { createSyncClient } from '@bhoomash/syncraft-client';
import { IndexedDBAdapter } from '@bhoomash/syncraft-storage';
const client = createSyncClient({
url: 'ws://localhost:8080',
roomId: 'project-room-1',
nodeId: 'user-alice',
storage: new IndexedDBAdapter({ dbName: 'my-app-storage' }),
autoConnect: true,
});
// Subscribe to state updates
client.subscribe((state) => {
console.log('Synchronized state:', state);
});
// Mutate local state
await client.set('document.title', 'Project Roadmap');
await client.set('document.tags.0', 'crdt');
// Inspect connection status
client.onStatusChange((status) => {
console.log('Connection status:', status); // 'connecting' | 'connected' | 'reconnecting' | 'disconnected'
});License
MIT © Bhoomash
