mirror of
https://github.com/wisplite/tether-ts.git
synced 2026-05-01 06:22:41 -05:00
hopefully this works
This commit is contained in:
@@ -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);
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user