Files
bookhoard/docs/developer/api/websocket/protocol.md
T
john-okeefe b44e4e4709 docs: remove Phase X placeholders from API documentation
Clean up API documentation files by removing Phase X references:

Remove 'API Explorer will be inserted here in Phase X' placeholders from:
- 70+ API endpoint documentation files
- Authentication endpoints (login, logout, register, refresh)
- User endpoints (profile, settings, password)
- Device endpoints (registration, sync, shelves)
- Library endpoints (CRUD, folders, visibility)
- Media endpoints (items, progress, highlights, notes)
- Admin endpoints (users, analytics)
- Sync endpoints (Kobo, KOReader)
- OPDS endpoints
- Scanner endpoints
- Queue endpoints

These placeholders were from planning documents and have no meaning
to API consumers. The documentation is now clean and ready for use.
2026-02-13 21:50:44 -05:00

1.7 KiB

WebSocket Protocol

Real-time sync events broadcast to connected clients.

Connect to WebSocket

Endpoint: WS /ws/sync?token=<token>

Connection Parameters

Parameter Type Required Description
token string Yes JWT authentication token

Example Connection

const ws = new WebSocket('wss://bookhoard.com/ws/sync?token=eyJhbG...');

Message Format

All messages are JSON objects with a type field.

Client → Server Messages

Ping (Heartbeat)

{
  "type": "ping"
}

Keep connection alive. Server responds with pong.

Server → Client Messages

Progress Update

{
  "type": "progress_update",
  "timestamp": "2026-01-31T10:00:00Z",
  "data": {
    "book_id": "uuid",
    "progress": {
      "percentage": 0.45678,
      "epubcfi": "epubcfi(/6/4/2:15)",
      "chapter": 3
    },
    "annotations": {}
  },
  "source_device": {
    "id": "device-uuid",
    "name": "My Kobo",
    "type": "kobo"
  }
}

Broadcast when any device updates reading progress.

Conflict Detected

{
  "type": "conflict",
  "timestamp": "2026-01-31T10:00:00Z",
  "data": {
    "book_id": "uuid",
    "conflict_id": "uuid",
    "conflict_type": "progress"
  }
}

Broadcast when a sync conflict is detected.

Pong

{
  "type": "pong"
}

Server response to client ping.

Connection Management

  • Heartbeat: Send ping every 30 seconds
  • Reconnect: Use exponential backoff if connection drops
  • Authentication: Token must be valid for connection
  • Rate Limits: 60 messages/minute per connection

Error Handling

{
  "type": "error",
  "message": "Invalid token",
  "code": "AUTH_FAILED"
}