hopefully this works

This commit is contained in:
2026-04-23 08:51:27 -05:00
parent 1159d9a459
commit 44fe4c63c4
2 changed files with 16 additions and 1 deletions
+12
View File
@@ -44,10 +44,22 @@ export class TetherClient {
}; };
sendMutation = (mutationName: string, params: any) => { sendMutation = (mutationName: string, params: any) => {
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);
});
}; };
} }
+4 -1
View File
@@ -8,7 +8,7 @@ export class WebSocketHandler {
private maxReconnectAttempts: number = 5; private maxReconnectAttempts: number = 5;
private reconnectInterval: number = 1000; private reconnectInterval: number = 1000;
private sendQueue: string[] = []; private sendQueue: string[] = [];
public onMutation: (data: any) => void = () => {};
startConnection = (url: string) => { startConnection = (url: string) => {
this.url = url; this.url = url;
this.ws = new WebSocket(url); this.ws = new WebSocket(url);
@@ -33,6 +33,8 @@ 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);
} }
@@ -68,4 +70,5 @@ export class WebSocketHandler {
} }
this.ws?.send(message); this.ws?.send(message);
}; };
} }