mirror of
https://github.com/wisplite/tether-ts.git
synced 2026-05-01 06:22:41 -05:00
need to add build, oops
This commit is contained in:
Vendored
+11
-2
@@ -6,16 +6,25 @@ export class TetherClient {
|
|||||||
this.websocketHandler.startConnection(url);
|
this.websocketHandler.startConnection(url);
|
||||||
this.websocketHandler.onQuery = (location, data) => {
|
this.websocketHandler.onQuery = (location, data) => {
|
||||||
if (location) {
|
if (location) {
|
||||||
const callback = this.subscribedQueries.get(location);
|
const { callback } = this.subscribedQueries.get(location) || { callback: () => { } };
|
||||||
callback?.(data);
|
callback?.(data);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
this.websocketHandler.onOpen = () => {
|
||||||
|
this.subscribedQueries.forEach(({ params }, queryName) => {
|
||||||
|
this.websocketHandler.send(JSON.stringify({
|
||||||
|
type: 'subscribe',
|
||||||
|
location: queryName,
|
||||||
|
params: params
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
};
|
||||||
};
|
};
|
||||||
disconnect = () => {
|
disconnect = () => {
|
||||||
this.websocketHandler.close();
|
this.websocketHandler.close();
|
||||||
};
|
};
|
||||||
subscribe = (queryName, params, callback) => {
|
subscribe = (queryName, params, callback) => {
|
||||||
this.subscribedQueries.set(queryName, callback);
|
this.subscribedQueries.set(queryName, { callback, params });
|
||||||
this.websocketHandler.send(JSON.stringify({
|
this.websocketHandler.send(JSON.stringify({
|
||||||
type: 'subscribe',
|
type: 'subscribe',
|
||||||
location: queryName,
|
location: queryName,
|
||||||
|
|||||||
Reference in New Issue
Block a user