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;
|
||||
subscribe: (queryName: string, params: any, callback: (data: any) => void) => 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) => {
|
||||
const mutation_id = crypto.randomUUID();
|
||||
this.websocketHandler.send(JSON.stringify({
|
||||
type: 'mutation',
|
||||
location: mutationName,
|
||||
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 reconnectInterval;
|
||||
private sendQueue;
|
||||
onMutation: (data: any) => void;
|
||||
startConnection: (url: string) => void;
|
||||
attemptReconnect: () => void;
|
||||
close: () => void;
|
||||
|
||||
Vendored
+4
@@ -8,6 +8,7 @@ export class WebSocketHandler {
|
||||
maxReconnectAttempts = 5;
|
||||
reconnectInterval = 1000;
|
||||
sendQueue = [];
|
||||
onMutation = () => { };
|
||||
startConnection = (url) => {
|
||||
this.url = url;
|
||||
this.ws = new WebSocket(url);
|
||||
@@ -26,6 +27,9 @@ export class WebSocketHandler {
|
||||
if (data.type === 'query') {
|
||||
this.onQuery(data.location, data.data);
|
||||
}
|
||||
else if (data.type === 'mutation') {
|
||||
this.onMutation(data.data);
|
||||
}
|
||||
else if (data.type === 'error') {
|
||||
console.error(data.error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user