Skip to content

Commit 051fdd3

Browse files
committed
docs: fix
1 parent 130407d commit 051fdd3

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

packages/loro-websocket/README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#
21
# loro-websocket
32

43
WebSocket client and a minimal SimpleServer for syncing Loro CRDTs. The client provides connection status events, auto‑reconnect with exponential backoff, latency tracking via ping/pong, safe fragmentation/reassembly for large updates, and seamless room rejoin across reconnects.
@@ -16,7 +15,8 @@ pnpm add loro-crdt
1615
```ts
1716
// In Node, provide a WebSocket implementation
1817
import { WebSocket } from "ws";
19-
(globalThis as any).WebSocket = WebSocket as unknown as typeof globalThis.WebSocket;
18+
(globalThis as any).WebSocket =
19+
WebSocket as unknown as typeof globalThis.WebSocket;
2020

2121
import { LoroWebsocketClient, ClientStatus } from "loro-websocket";
2222
import { createLoroAdaptor } from "loro-adaptors";
@@ -47,11 +47,14 @@ offStatus();
4747
import { LoroWebsocketClient } from "loro-websocket";
4848
import { EloLoroAdaptor } from "loro-adaptors";
4949

50-
const key = new Uint8Array(32); key[0] = 1;
50+
const key = new Uint8Array(32);
51+
key[0] = 1;
5152
const client = new LoroWebsocketClient({ url: "ws://localhost:8787" });
5253
await client.waitConnected();
5354

54-
const adaptor = new EloLoroAdaptor({ getPrivateKey: async () => ({ keyId: "k1", key }) });
55+
const adaptor = new EloLoroAdaptor({
56+
getPrivateKey: async () => ({ keyId: "k1", key }),
57+
});
5558
await client.join({ roomId: "secure-room", crdtAdaptor: adaptor });
5659

5760
adaptor.getDoc().getText("t").insert(0, "secret");
@@ -160,6 +163,7 @@ await server.start();
160163
## Examples
161164

162165
- Status and reconnect
166+
163167
```ts
164168
const client = new LoroWebsocketClient({ url: "ws://localhost:8787" });
165169
client.onStatusChange(s => console.log("status:", s));
@@ -172,6 +176,7 @@ await client.connect(); // status: Connecting → Connected
172176
```
173177

174178
- Latency
179+
175180
```ts
176181
const off = client.onLatency(ms => console.log("latency:", ms));
177182
await client.ping(2000);
@@ -180,6 +185,7 @@ off();
180185
```
181186

182187
- Join with auth
188+
183189
```ts
184190
await client.join({
185191
roomId: "project-123",

0 commit comments

Comments
 (0)