mirror of
https://github.com/wisplite/tether-ts.git
synced 2026-05-01 06:22:41 -05:00
ahhhh
This commit is contained in:
Vendored
+1
-1
@@ -5,5 +5,5 @@ export declare class TetherClient {
|
|||||||
disconnect: () => void;
|
disconnect: () => void;
|
||||||
subscribe: (queryName: string, params: any, callback: (data: any) => void) => void;
|
subscribe: (queryName: string, params: any, callback: (data: any) => void) => void;
|
||||||
unsubscribe: (query: string) => void;
|
unsubscribe: (query: string) => void;
|
||||||
sendMutation: (mutationName: string, params: any) => void;
|
sendMutation: (mutationName: string, params: any) => Promise<unknown>;
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+12
@@ -39,10 +39,22 @@ export class TetherClient {
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
sendMutation = (mutationName, params) => {
|
sendMutation = (mutationName, params) => {
|
||||||
|
const mutation_id = crypto.randomUUID();
|
||||||
this.websocketHandler.send(JSON.stringify({
|
this.websocketHandler.send(JSON.stringify({
|
||||||
type: 'mutation',
|
type: 'mutation',
|
||||||
location: mutationName,
|
location: mutationName,
|
||||||
params: params,
|
params: params,
|
||||||
|
mutation_id: mutation_id
|
||||||
}));
|
}));
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.websocketHandler.onMutation = (data) => {
|
||||||
|
if (data.mutation_id === mutation_id) {
|
||||||
|
resolve(data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
setTimeout(() => {
|
||||||
|
reject(new Error('Mutation timeout'));
|
||||||
|
}, 10000);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
@@ -8,6 +8,7 @@ export declare class WebSocketHandler {
|
|||||||
private maxReconnectAttempts;
|
private maxReconnectAttempts;
|
||||||
private reconnectInterval;
|
private reconnectInterval;
|
||||||
private sendQueue;
|
private sendQueue;
|
||||||
|
onMutation: (data: any) => void;
|
||||||
startConnection: (url: string) => void;
|
startConnection: (url: string) => void;
|
||||||
attemptReconnect: () => void;
|
attemptReconnect: () => void;
|
||||||
close: () => void;
|
close: () => void;
|
||||||
|
|||||||
Vendored
+4
@@ -8,6 +8,7 @@ export class WebSocketHandler {
|
|||||||
maxReconnectAttempts = 5;
|
maxReconnectAttempts = 5;
|
||||||
reconnectInterval = 1000;
|
reconnectInterval = 1000;
|
||||||
sendQueue = [];
|
sendQueue = [];
|
||||||
|
onMutation = () => { };
|
||||||
startConnection = (url) => {
|
startConnection = (url) => {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.ws = new WebSocket(url);
|
this.ws = new WebSocket(url);
|
||||||
@@ -26,6 +27,9 @@ export class WebSocketHandler {
|
|||||||
if (data.type === 'query') {
|
if (data.type === 'query') {
|
||||||
this.onQuery(data.location, data.data);
|
this.onQuery(data.location, data.data);
|
||||||
}
|
}
|
||||||
|
else if (data.type === 'mutation') {
|
||||||
|
this.onMutation(data.data);
|
||||||
|
}
|
||||||
else if (data.type === 'error') {
|
else if (data.type === 'error') {
|
||||||
console.error(data.error);
|
console.error(data.error);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user