From 82f7877c2a839dc403b65de224af0564952b92f1 Mon Sep 17 00:00:00 2001 From: Zixuan Chen Date: Sun, 11 Jan 2026 11:07:54 +0000 Subject: [PATCH] chore(loro-websocket): default ping interval to 20s Co-authored-by: lody --- llms.md | 2 +- packages/loro-websocket/README.md | 4 ++-- packages/loro-websocket/src/client/index.ts | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/llms.md b/llms.md index e6d4539..82418dc 100644 --- a/llms.md +++ b/llms.md @@ -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. }); diff --git a/packages/loro-websocket/README.md b/packages/loro-websocket/README.md index 5d21ebd..22595e6 100644 --- a/packages/loro-websocket/README.md +++ b/packages/loro-websocket/README.md @@ -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) } @@ -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 diff --git a/packages/loro-websocket/src/client/index.ts b/packages/loro-websocket/src/client/index.ts index d93e032..de9f11e 100644 --- a/packages/loro-websocket/src/client/index.ts +++ b/packages/loro-websocket/src/client/index.ts @@ -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; @@ -1733,7 +1733,7 @@ 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; @@ -1741,7 +1741,7 @@ function getPingIntervalMs(opts: { if (opts.disablePing) return undefined; const v = opts.pingIntervalMs; if (isPositive(v)) return v; - return 30_000; + return 20_000; } function createLoroWebsocketClientRoom(opts: {