Redo the message protocols to work with SSE data directly

This commit is contained in:
Infi
2024-08-24 19:52:53 +02:00
parent c7a52e8edb
commit 29e3c6acee
8 changed files with 98 additions and 54 deletions
+7 -3
View File
@@ -3,18 +3,22 @@ class SSEConnection {
constructor() {
this.socket = new EventSource('/sse', );
this.socket.addEventListener('close', (e) => {
this.socket.addEventListener('close', (event) => {
console.log("Closing SSE connection.")
this.socket.close()
});
this.socket.onmessage = (event) => {
this.socket.addEventListener('switch-channel', (event) => {
updateChannelHint(JSON.parse(event.data).channel)
});
this.socket.addEventListener('new-message', (event) => {
let eventData = JSON.parse(event.data);
for (let message of eventData.messages)
{
addMessage(message);
}
};
});
}
send(message) {