TypeScript SDK for browser and Node.js. Connect, listen, react — zero boilerplate.
npm install @hookwire/sdk
import { HookwireClient } from '@hookwire/sdk'; const client = new HookwireClient({ // Your channel name (the random string) channelName: 'abc123def456', // Optional — defaults to https://hookwire.dev baseUrl: 'http://localhost:8787', }); // Subscribe to real-time events client.onEvent(event => { console.log('New event #', event.seq); console.log(event.body.data); }); // Connect (fetches history, then opens WebSocket) await client.connect(); // Later… client.disconnect();
| Option | Type | Default | Description |
|---|---|---|---|
channelName | string | — | Your channel name (required) |
baseUrl | string | https://hookwire.dev | API base URL |
autoReconnect | boolean | true | Reconnect on disconnect |
reconnectDelay | number | 1000 | Initial delay in ms (exponential backoff) |
| Method | Returns | Description |
|---|---|---|
connect() | Promise<void> | Fetch history + open WebSocket |
disconnect() | void | Close WebSocket, stop reconnect |
onEvent(handler) | () => void | Subscribe to events. Returns unsubscribe fn. |
getHistory({ limit, afterSeq }) | Promise<ChannelEvent[]> | Fetch event history |
interface ChannelEvent { id: string; // evt_xxx seq: number; // Monotonically increasing received_at: string; // ISO timestamp method: string; // HTTP method headers: Record<string, string>; body: { encoding: 'utf8' | 'base64'; content_type?: string; data: string; size: number; truncated: boolean; }; summary?: { title: string; subtitle?: string }; }
If you prefer SSE over WebSocket, use the standard EventSource API — no SDK needed:
const es = new EventSource('https://hookwire.dev/ch/abc123/sse'); es.onmessage = (event) => { const data = JSON.parse(event.data); console.log('SSE event #', data.seq); };
Both WebSocket and SSE support ?since= for replaying missed events:
| URL | Behavior |
|---|---|
/ch/:name/ws | Real-time only (no history) |
/ch/:name/ws?since=0 | Full replay + real-time |
/ch/:name/ws?since=42 | Replay from seq 42 + real-time |
/ch/:name/sse | Real-time only |
/ch/:name/sse?since=0 | Full replay + real-time |
The SDK automatically appends ?since= on reconnect — you never miss events that are still in the retention window (100 events / 24 hours).