@moku-labs/web 2.2.1 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1763,6 +1763,20 @@ interface ChannelOptions<T> {
1763
1763
  * order) on seed, closing the connect→load race. Defaults to `false` (deliver live).
1764
1764
  */
1765
1765
  bufferUntilSeed?: boolean;
1766
+ /**
1767
+ * Guard called on every socket close before the reconnect backoff is scheduled. Return `false`
1768
+ * to suppress reconnection (e.g. stop on a terminal close code like `4401` for 401 Unauthorized
1769
+ * / channel-not-found). The default — when omitted — always reconnects. The guard receives the
1770
+ * `CloseEvent`, so callers can inspect `event.code` / `event.reason` / `event.wasClean`.
1771
+ *
1772
+ * @param event - The `CloseEvent` from the closed socket.
1773
+ * @returns `true` (or `undefined`) to reconnect; `false` to stop permanently.
1774
+ * @example
1775
+ * ```ts
1776
+ * shouldReconnect: (event) => event.code !== 4401
1777
+ * ```
1778
+ */
1779
+ shouldReconnect?: (event: CloseEvent) => boolean;
1766
1780
  }
1767
1781
  /** A live realtime channel (the surface returned by {@link createChannel}). */
1768
1782
  interface Channel<T> {
package/dist/browser.mjs CHANGED
@@ -4500,10 +4500,12 @@ function createChannel(options) {
4500
4500
  ws.addEventListener("open", () => {
4501
4501
  reconnectAttempts = 0;
4502
4502
  });
4503
- ws.addEventListener("close", () => {
4503
+ ws.addEventListener("close", (event) => {
4504
4504
  if (socket !== ws || desiredId === void 0) return;
4505
4505
  socket = void 0;
4506
- if (reconnectCfg) scheduleReconnect();
4506
+ if (!reconnectCfg) return;
4507
+ if (options.shouldReconnect?.(event) === false) return;
4508
+ scheduleReconnect();
4507
4509
  });
4508
4510
  }
4509
4511
  /**
package/dist/index.cjs CHANGED
@@ -11206,10 +11206,12 @@ function createChannel(options) {
11206
11206
  ws.addEventListener("open", () => {
11207
11207
  reconnectAttempts = 0;
11208
11208
  });
11209
- ws.addEventListener("close", () => {
11209
+ ws.addEventListener("close", (event) => {
11210
11210
  if (socket !== ws || desiredId === void 0) return;
11211
11211
  socket = void 0;
11212
- if (reconnectCfg) scheduleReconnect();
11212
+ if (!reconnectCfg) return;
11213
+ if (options.shouldReconnect?.(event) === false) return;
11214
+ scheduleReconnect();
11213
11215
  });
11214
11216
  }
11215
11217
  /**
package/dist/index.d.cts CHANGED
@@ -3683,6 +3683,20 @@ interface ChannelOptions<T> {
3683
3683
  * order) on seed, closing the connect→load race. Defaults to `false` (deliver live).
3684
3684
  */
3685
3685
  bufferUntilSeed?: boolean;
3686
+ /**
3687
+ * Guard called on every socket close before the reconnect backoff is scheduled. Return `false`
3688
+ * to suppress reconnection (e.g. stop on a terminal close code like `4401` for 401 Unauthorized
3689
+ * / channel-not-found). The default — when omitted — always reconnects. The guard receives the
3690
+ * `CloseEvent`, so callers can inspect `event.code` / `event.reason` / `event.wasClean`.
3691
+ *
3692
+ * @param event - The `CloseEvent` from the closed socket.
3693
+ * @returns `true` (or `undefined`) to reconnect; `false` to stop permanently.
3694
+ * @example
3695
+ * ```ts
3696
+ * shouldReconnect: (event) => event.code !== 4401
3697
+ * ```
3698
+ */
3699
+ shouldReconnect?: (event: CloseEvent) => boolean;
3686
3700
  }
3687
3701
  /** A live realtime channel (the surface returned by {@link createChannel}). */
3688
3702
  interface Channel<T> {
package/dist/index.d.mts CHANGED
@@ -3681,6 +3681,20 @@ interface ChannelOptions<T> {
3681
3681
  * order) on seed, closing the connect→load race. Defaults to `false` (deliver live).
3682
3682
  */
3683
3683
  bufferUntilSeed?: boolean;
3684
+ /**
3685
+ * Guard called on every socket close before the reconnect backoff is scheduled. Return `false`
3686
+ * to suppress reconnection (e.g. stop on a terminal close code like `4401` for 401 Unauthorized
3687
+ * / channel-not-found). The default — when omitted — always reconnects. The guard receives the
3688
+ * `CloseEvent`, so callers can inspect `event.code` / `event.reason` / `event.wasClean`.
3689
+ *
3690
+ * @param event - The `CloseEvent` from the closed socket.
3691
+ * @returns `true` (or `undefined`) to reconnect; `false` to stop permanently.
3692
+ * @example
3693
+ * ```ts
3694
+ * shouldReconnect: (event) => event.code !== 4401
3695
+ * ```
3696
+ */
3697
+ shouldReconnect?: (event: CloseEvent) => boolean;
3684
3698
  }
3685
3699
  /** A live realtime channel (the surface returned by {@link createChannel}). */
3686
3700
  interface Channel<T> {
package/dist/index.mjs CHANGED
@@ -11193,10 +11193,12 @@ function createChannel(options) {
11193
11193
  ws.addEventListener("open", () => {
11194
11194
  reconnectAttempts = 0;
11195
11195
  });
11196
- ws.addEventListener("close", () => {
11196
+ ws.addEventListener("close", (event) => {
11197
11197
  if (socket !== ws || desiredId === void 0) return;
11198
11198
  socket = void 0;
11199
- if (reconnectCfg) scheduleReconnect();
11199
+ if (!reconnectCfg) return;
11200
+ if (options.shouldReconnect?.(event) === false) return;
11201
+ scheduleReconnect();
11200
11202
  });
11201
11203
  }
11202
11204
  /**
package/package.json CHANGED
@@ -132,5 +132,5 @@
132
132
  "test:build-e2e": "bun test src/plugins/build/__tests__/e2e/",
133
133
  "test:coverage": "vitest run --project unit --project integration --coverage"
134
134
  },
135
- "version": "2.2.1"
135
+ "version": "2.2.2"
136
136
  }