mirror of
https://github.com/wisplite/tether-ts.git
synced 2026-05-01 06:22:41 -05:00
pass callbacks to client
This commit is contained in:
Vendored
+2
-6
@@ -1,8 +1,8 @@
|
||||
export class WebSocketHandler {
|
||||
ws = null;
|
||||
url = '';
|
||||
subscribedQueries = new Map();
|
||||
onOpen = () => { };
|
||||
onQuery = () => { };
|
||||
onClose = () => { };
|
||||
reconnectAttempts = 0;
|
||||
maxReconnectAttempts = 5;
|
||||
@@ -24,11 +24,7 @@ export class WebSocketHandler {
|
||||
ws.onmessage = (event) => {
|
||||
const data = JSON.parse(String(event.data));
|
||||
if (data.type === 'query') {
|
||||
this.subscribedQueries.forEach((callback, query) => {
|
||||
if (data.query === query) {
|
||||
callback(data.data);
|
||||
}
|
||||
});
|
||||
this.onQuery(data.location, data.data);
|
||||
}
|
||||
else if (data.type === 'error') {
|
||||
console.error(data.error);
|
||||
|
||||
Reference in New Issue
Block a user