Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion llms.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ Adaptors bridge the client to actual CRDT state:
```ts
new LoroWebsocketClient({
url: string, // Required ws:// or wss:// endpoint.
pingIntervalMs?: number, // Default 30_000 ms.
pingIntervalMs?: number, // Default 20_000 ms.
disablePing?: boolean, // Skip periodic ping/pong entirely.
onWsClose?: () => void, // Invoked on low-level close before status change.
});
Expand Down
4 changes: 2 additions & 2 deletions packages/loro-websocket/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ new LoroWebsocketClient(options: LoroWebsocketClientOptions)

interface LoroWebsocketClientOptions {
url: string; // WebSocket URL (ws:// or wss://)
pingIntervalMs?: number; // Periodic ping interval (default 30_000ms)
pingIntervalMs?: number; // Periodic ping interval (default 20_000ms)
disablePing?: boolean; // Disable periodic pings entirely
onWsClose?: () => void; // Low‑level ws close callback (before status transitions)
}
Expand Down Expand Up @@ -117,7 +117,7 @@ type ClientStatusValue = typeof ClientStatus[keyof typeof ClientStatus];
## Latency & Ping/Pong

- Periodic pings
- By default, the client sends a text `"ping"` every 30s (configurable via `pingIntervalMs`) and expects a `"pong"`. This keeps the connection alive and measures round‑trip latency.
- By default, the client sends a text `"ping"` every 20s (configurable via `pingIntervalMs`) and expects a `"pong"`. This keeps the connection alive and measures round‑trip latency.
- Set `disablePing: true` to turn off the timer.

- On‑demand ping
Expand Down
6 changes: 3 additions & 3 deletions packages/loro-websocket/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export type ClientStatusValue =
export interface LoroWebsocketClientOptions {
/** WebSocket URL (ws:// or wss://). */
url: string;
/** Optional custom ping interval. Defaults to 30s. Set with `disablePing` to stop timers. */
/** Optional custom ping interval. Defaults to 20s. Set with `disablePing` to stop timers. */
pingIntervalMs?: number;
/** Ping timeout; after two consecutive misses the client will force-close and reconnect. Defaults to 10s. */
pingTimeoutMs?: number;
Expand Down Expand Up @@ -1733,15 +1733,15 @@ function isPositive(v: unknown): v is number {
return typeof v === "number" && isFinite(v) && v > 0;
}

// Use default 30s unless disabled
// Use default 20s unless disabled
function getPingIntervalMs(opts: {
pingIntervalMs?: number;
disablePing?: boolean;
}): number | undefined {
if (opts.disablePing) return undefined;
const v = opts.pingIntervalMs;
if (isPositive(v)) return v;
return 30_000;
return 20_000;
}

function createLoroWebsocketClientRoom(opts: {
Expand Down