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) => {
|
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);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -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);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user