From 00eeff128298d5d79d76c22ba609f83c09f5817f Mon Sep 17 00:00:00 2001 From: wisplite Date: Wed, 8 Apr 2026 15:09:08 -0500 Subject: [PATCH] added proper connection check --- dist/index.js | 8 ++++---- src/index.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index 5c597fd..b076d71 100644 --- a/dist/index.js +++ b/dist/index.js @@ -24,7 +24,7 @@ export class TetherClient { }; }; disconnect = () => { - if (!this.ws) { + if (!this.ws || this.ws.readyState !== WebSocket.OPEN) { throw new Error('Not connected to Tether'); } this.ws.close(); @@ -32,7 +32,7 @@ export class TetherClient { }; subscribe = (query, callback) => { this.subscribedQueries.set(query, callback); - if (!this.ws) { + if (!this.ws || this.ws.readyState !== WebSocket.OPEN) { throw new Error('Not connected to Tether'); } this.ws.send(JSON.stringify({ @@ -42,7 +42,7 @@ export class TetherClient { }; unsubscribe = (query) => { this.subscribedQueries.delete(query); - if (!this.ws) { + if (!this.ws || this.ws.readyState !== WebSocket.OPEN) { throw new Error('Not connected to Tether'); } this.ws.send(JSON.stringify({ @@ -51,7 +51,7 @@ export class TetherClient { })); }; sendMutation = (mutationName, params) => { - if (!this.ws) { + if (!this.ws || this.ws.readyState !== WebSocket.OPEN) { throw new Error('Not connected to Tether'); } this.ws.send(JSON.stringify({ diff --git a/src/index.ts b/src/index.ts index eaa6765..4e83ee4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -25,7 +25,7 @@ export class TetherClient { }; disconnect = () => { - if (!this.ws) { + if (!this.ws || this.ws.readyState !== WebSocket.OPEN) { throw new Error('Not connected to Tether'); } this.ws.close(); @@ -34,7 +34,7 @@ export class TetherClient { subscribe = (query: string, callback: (data: any) => void) => { this.subscribedQueries.set(query, callback); - if (!this.ws) { + if (!this.ws || this.ws.readyState !== WebSocket.OPEN) { throw new Error('Not connected to Tether'); } this.ws.send(JSON.stringify({ @@ -45,7 +45,7 @@ export class TetherClient { unsubscribe = (query: string) => { this.subscribedQueries.delete(query); - if (!this.ws) { + if (!this.ws || this.ws.readyState !== WebSocket.OPEN) { throw new Error('Not connected to Tether'); } this.ws.send(JSON.stringify({ @@ -55,7 +55,7 @@ export class TetherClient { }; sendMutation = (mutationName: string, params: any) => { - if (!this.ws) { + if (!this.ws || this.ws.readyState !== WebSocket.OPEN) { throw new Error('Not connected to Tether'); } this.ws.send(JSON.stringify({