diff --git a/src/gateway.ts b/src/gateway.ts index ba20dd5..1865572 100644 --- a/src/gateway.ts +++ b/src/gateway.ts @@ -114,7 +114,7 @@ export class GatewayPresence { ws.onerror = () => void this.handleClose(4000).catch(() => {}); liveSocket = ws; // Safety: if HELLO never arrives, the alarm resets the zombie socket. - await this.ctx.setAlarm(Date.now() + 30_000); + await this.ctx.storage.setAlarm(Date.now() + 30_000); } private killSocket(ws: WebSocket): void { @@ -129,7 +129,7 @@ export class GatewayPresence { const delay = session.reconnectBackoffMs; session.reconnectBackoffMs = nextBackoff(delay); await this.ctx.storage.put('session', session); - await this.ctx.setAlarm(Date.now() + delay); + await this.ctx.storage.setAlarm(Date.now() + delay); } private async sendHeartbeat(session: GatewaySession): Promise { @@ -193,7 +193,7 @@ export class GatewayPresence { }, })); } - await this.ctx.setAlarm(Date.now() + jitter(session.heartbeatIntervalMs)); + await this.ctx.storage.setAlarm(Date.now() + jitter(session.heartbeatIntervalMs)); } else if (op === 11) { session.awaitingAck = false; await this.ctx.storage.put('session', session); diff --git a/src/workers-types.d.ts b/src/workers-types.d.ts index eb6df59..502260c 100644 --- a/src/workers-types.d.ts +++ b/src/workers-types.d.ts @@ -8,14 +8,12 @@ declare interface DurableObjectStorage { get(key: string): Promise; put(key: string, value: unknown): Promise; deleteAll(): Promise; + setAlarm(time: number | Date): Promise; + getAlarm(): Promise; } declare interface DurableObjectState { storage: DurableObjectStorage; - acceptWebSocket(ws: WebSocket): void; - getWebSockets(): WebSocket[]; - setAlarm(time: number | Date): Promise; - getAlarm(): Promise; } declare interface DurableObjectId {