mirror of
https://github.com/wisplite/tether-ts.git
synced 2026-05-01 06:22:41 -05:00
added proper connection check
This commit is contained in:
Vendored
+4
-4
@@ -24,7 +24,7 @@ export class TetherClient {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
disconnect = () => {
|
disconnect = () => {
|
||||||
if (!this.ws) {
|
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
||||||
throw new Error('Not connected to Tether');
|
throw new Error('Not connected to Tether');
|
||||||
}
|
}
|
||||||
this.ws.close();
|
this.ws.close();
|
||||||
@@ -32,7 +32,7 @@ export class TetherClient {
|
|||||||
};
|
};
|
||||||
subscribe = (query, callback) => {
|
subscribe = (query, callback) => {
|
||||||
this.subscribedQueries.set(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');
|
throw new Error('Not connected to Tether');
|
||||||
}
|
}
|
||||||
this.ws.send(JSON.stringify({
|
this.ws.send(JSON.stringify({
|
||||||
@@ -42,7 +42,7 @@ export class TetherClient {
|
|||||||
};
|
};
|
||||||
unsubscribe = (query) => {
|
unsubscribe = (query) => {
|
||||||
this.subscribedQueries.delete(query);
|
this.subscribedQueries.delete(query);
|
||||||
if (!this.ws) {
|
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
||||||
throw new Error('Not connected to Tether');
|
throw new Error('Not connected to Tether');
|
||||||
}
|
}
|
||||||
this.ws.send(JSON.stringify({
|
this.ws.send(JSON.stringify({
|
||||||
@@ -51,7 +51,7 @@ export class TetherClient {
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
sendMutation = (mutationName, params) => {
|
sendMutation = (mutationName, params) => {
|
||||||
if (!this.ws) {
|
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
||||||
throw new Error('Not connected to Tether');
|
throw new Error('Not connected to Tether');
|
||||||
}
|
}
|
||||||
this.ws.send(JSON.stringify({
|
this.ws.send(JSON.stringify({
|
||||||
|
|||||||
+4
-4
@@ -25,7 +25,7 @@ export class TetherClient {
|
|||||||
};
|
};
|
||||||
|
|
||||||
disconnect = () => {
|
disconnect = () => {
|
||||||
if (!this.ws) {
|
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
||||||
throw new Error('Not connected to Tether');
|
throw new Error('Not connected to Tether');
|
||||||
}
|
}
|
||||||
this.ws.close();
|
this.ws.close();
|
||||||
@@ -34,7 +34,7 @@ export class TetherClient {
|
|||||||
|
|
||||||
subscribe = (query: string, callback: (data: any) => void) => {
|
subscribe = (query: string, callback: (data: any) => void) => {
|
||||||
this.subscribedQueries.set(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');
|
throw new Error('Not connected to Tether');
|
||||||
}
|
}
|
||||||
this.ws.send(JSON.stringify({
|
this.ws.send(JSON.stringify({
|
||||||
@@ -45,7 +45,7 @@ export class TetherClient {
|
|||||||
|
|
||||||
unsubscribe = (query: string) => {
|
unsubscribe = (query: string) => {
|
||||||
this.subscribedQueries.delete(query);
|
this.subscribedQueries.delete(query);
|
||||||
if (!this.ws) {
|
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
||||||
throw new Error('Not connected to Tether');
|
throw new Error('Not connected to Tether');
|
||||||
}
|
}
|
||||||
this.ws.send(JSON.stringify({
|
this.ws.send(JSON.stringify({
|
||||||
@@ -55,7 +55,7 @@ export class TetherClient {
|
|||||||
};
|
};
|
||||||
|
|
||||||
sendMutation = (mutationName: string, params: any) => {
|
sendMutation = (mutationName: string, params: any) => {
|
||||||
if (!this.ws) {
|
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
||||||
throw new Error('Not connected to Tether');
|
throw new Error('Not connected to Tether');
|
||||||
}
|
}
|
||||||
this.ws.send(JSON.stringify({
|
this.ws.send(JSON.stringify({
|
||||||
|
|||||||
Reference in New Issue
Block a user