Skip to content

Commit

Permalink
Merge branch 'main' of github.com:numan-ai/explainable_frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
Clementine2722 committed Jul 9, 2024
2 parents 29d6264 + f274fb2 commit daa2b09
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ class WebSocketClient {
this.ws.onmessage = (event) => {
const message = event.data;
const data = JSON.parse(message);
console.log('Got message', data);
if (this.messageCallbacks[data.type]) {
this.messageCallbacks[data.type].forEach(callback => callback(data.data));
if (Array.isArray(data)) {
data.forEach(this.processMessage);
} else {
this.processMessage(data);
}
};

Expand All @@ -75,6 +76,13 @@ class WebSocketClient {
};
}

private processMessage = (data: any) => {
console.log('Got message', data);
if (this.messageCallbacks[data.type]) {
this.messageCallbacks[data.type].forEach(callback => callback(data.data));
}
}

public send(message: string) {
if (!this.ws) {
return;
Expand Down

0 comments on commit daa2b09

Please sign in to comment.