Skip to content

Commit a7d7811

Browse files
authored
feat: add onWsClose callback to LoroWebsocketClient options (#2)
1 parent 2743aa5 commit a7d7811

File tree

1 file changed

+2
-1
lines changed
  • packages/loro-websocket/src/client

1 file changed

+2
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class LoroWebsocketClient {
6363
}> = [];
6464

6565
constructor(
66-
private ops: { url: string; pingIntervalMs?: number; disablePing?: boolean }
66+
private ops: { url: string; pingIntervalMs?: number; disablePing?: boolean, onWsClose?: () => void }
6767
) {
6868
this.connectedPromise = new Promise<void>((resolve, reject) => {
6969
this.ws = new WebSocket(this.ops.url);
@@ -102,6 +102,7 @@ export class LoroWebsocketClient {
102102
// Clear timers and pending waiters on close
103103
this.ws.addEventListener('close', () => {
104104
this.clearPingTimer();
105+
this.ops.onWsClose?.();
105106
this.rejectAllPingWaiters(new Error("WebSocket closed"));
106107
});
107108
}

0 commit comments

Comments
 (0)