mirror of
https://github.com/wisplite/tether-ts.git
synced 2026-05-01 06:22:41 -05:00
33 lines
961 B
JavaScript
33 lines
961 B
JavaScript
import { WebSocketHandler } from './utils/websocket.js';
|
|
export class TetherClient {
|
|
websocketHandler = new WebSocketHandler();
|
|
subscribedQueries = new Map();
|
|
connect = (url) => {
|
|
this.websocketHandler.startConnection(url);
|
|
};
|
|
disconnect = () => {
|
|
this.websocketHandler.close();
|
|
};
|
|
subscribe = (query, callback) => {
|
|
this.subscribedQueries.set(query, callback);
|
|
this.websocketHandler.send(JSON.stringify({
|
|
type: 'subscribe',
|
|
query: query
|
|
}));
|
|
};
|
|
unsubscribe = (query) => {
|
|
this.subscribedQueries.delete(query);
|
|
this.websocketHandler.send(JSON.stringify({
|
|
type: 'unsubscribe',
|
|
query: query
|
|
}));
|
|
};
|
|
sendMutation = (mutationName, params) => {
|
|
this.websocketHandler.send(JSON.stringify({
|
|
type: 'mutation',
|
|
name: mutationName,
|
|
payload: params,
|
|
}));
|
|
};
|
|
}
|