Sync Clients
kSync provides multiple synchronization clients to sync data between instances. Choose between real-time WebSocket synchronization or Git-like pull/push synchronization.Sync Client Interface
WebSocketSyncClient
Real-time bidirectional synchronization using WebSockets.Constructor
url(string): WebSocket server URLoptions(optional):auth?: Authentication configurationreconnect?(boolean): Auto-reconnect on disconnect (default: true)heartbeat?(number): Heartbeat interval in ms (default: 30000)compression?(boolean): Enable compression (default: false)
Authentication
Methods
connect()
Connects to the WebSocket server.
disconnect()
Disconnects from the WebSocket server.
send(event)
Sends an event to connected peers.
Event Listeners
Complete Example
GitSyncClient
Git-like pull/push synchronization for offline-first applications.Constructor
url(string): Server URL for sync operationsauth?: Authentication configurationbranch?(string): Branch name (default: ‘main’)pullInterval?(number): Auto-pull interval in ms (default: 0 = disabled)compression?(boolean): Enable compression (default: true)
Methods
pull()
Pulls latest events from the server.
push()
Pushes local events to the server.
sync()
Performs a full sync (pull + push).
clone(url, branch?)
Clones a repository from a remote server.
Conflict Resolution
Handle merge conflicts when events conflict:Branching
Work with multiple branches:Complete Example
P2PSyncClient
Peer-to-peer synchronization without a central server.Constructor
peerId(string): Unique identifier for this peerdiscoveryMethod(‘mdns’ | ‘dht’ | ‘manual’): How to discover peersport?(number): Port for P2P communicationencryption?(boolean): Enable end-to-end encryption

