diff --git a/src/gateway/client.e2e.test.ts b/src/gateway/client.e2e.test.ts index 4a4f15f815e..7fc48048304 100644 --- a/src/gateway/client.e2e.test.ts +++ b/src/gateway/client.e2e.test.ts @@ -70,6 +70,7 @@ describe("GatewayClient", () => { const client = new GatewayClient({ url: `ws://127.0.0.1:${port}`, connectDelayMs: 0, + tickWatchMinIntervalMs: 5, onClose: (code, reason) => resolve({ code, reason }), }); client.start(); diff --git a/src/gateway/client.ts b/src/gateway/client.ts index d19824c6abf..96f5f6bb482 100644 --- a/src/gateway/client.ts +++ b/src/gateway/client.ts @@ -41,6 +41,7 @@ type Pending = { export type GatewayClientOptions = { url?: string; // ws://127.0.0.1:18789 connectDelayMs?: number; + tickWatchMinIntervalMs?: number; token?: string; password?: string; instanceId?: string; @@ -376,7 +377,12 @@ export class GatewayClient { if (this.tickTimer) { clearInterval(this.tickTimer); } - const interval = Math.max(this.tickIntervalMs, 1000); + const rawMinInterval = this.opts.tickWatchMinIntervalMs; + const minInterval = + typeof rawMinInterval === "number" && Number.isFinite(rawMinInterval) + ? Math.max(1, Math.min(30_000, rawMinInterval)) + : 1000; + const interval = Math.max(this.tickIntervalMs, minInterval); this.tickTimer = setInterval(() => { if (this.closed) { return;