Skip to content

Commit edf4065

Browse files
lodyai[bot]zxch3nlody-ai
authored
chore(loro-websocket): default ping interval to 20s (#52)
Co-authored-by: Zixuan Chen <remch183@outlook.com> Co-authored-by: lody <agent@lody.ai>
1 parent 206fa93 commit edf4065

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

llms.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ Adaptors bridge the client to actual CRDT state:
197197
```ts
198198
new LoroWebsocketClient({
199199
url: string, // Required ws:// or wss:// endpoint.
200-
pingIntervalMs?: number, // Default 30_000 ms.
200+
pingIntervalMs?: number, // Default 20_000 ms.
201201
disablePing?: boolean, // Skip periodic ping/pong entirely.
202202
onWsClose?: () => void, // Invoked on low-level close before status change.
203203
});

packages/loro-websocket/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ new LoroWebsocketClient(options: LoroWebsocketClientOptions)
6868

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

119119
- Periodic pings
120-
- 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.
120+
- 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.
121121
- Set `disablePing: true` to turn off the timer.
122122

123123
- On‑demand ping

packages/loro-websocket/src/client/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export type ClientStatusValue =
9898
export interface LoroWebsocketClientOptions {
9999
/** WebSocket URL (ws:// or wss://). */
100100
url: string;
101-
/** Optional custom ping interval. Defaults to 30s. Set with `disablePing` to stop timers. */
101+
/** Optional custom ping interval. Defaults to 20s. Set with `disablePing` to stop timers. */
102102
pingIntervalMs?: number;
103103
/** Ping timeout; after two consecutive misses the client will force-close and reconnect. Defaults to 10s. */
104104
pingTimeoutMs?: number;
@@ -1733,15 +1733,15 @@ function isPositive(v: unknown): v is number {
17331733
return typeof v === "number" && isFinite(v) && v > 0;
17341734
}
17351735

1736-
// Use default 30s unless disabled
1736+
// Use default 20s unless disabled
17371737
function getPingIntervalMs(opts: {
17381738
pingIntervalMs?: number;
17391739
disablePing?: boolean;
17401740
}): number | undefined {
17411741
if (opts.disablePing) return undefined;
17421742
const v = opts.pingIntervalMs;
17431743
if (isPositive(v)) return v;
1744-
return 30_000;
1744+
return 20_000;
17451745
}
17461746

17471747
function createLoroWebsocketClientRoom(opts: {

0 commit comments

Comments
 (0)