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) => {
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);
});
};
}
+4 -1
View File
@@ -8,7 +8,7 @@ export class WebSocketHandler {
private maxReconnectAttempts: number = 5;
private reconnectInterval: number = 1000;
private sendQueue: string[] = [];
public onMutation: (data: any) => void = () => {};
startConnection = (url: string) => {
this.url = url;
this.ws = new WebSocket(url);
@@ -33,6 +33,8 @@ 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);
}
@@ -68,4 +70,5 @@ export class WebSocketHandler {
}
this.ws?.send(message);
};
}