Move to SSE from websocket
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/* fonts */
|
||||
@font-face {
|
||||
font-family: Lodestone;
|
||||
src: url('files/FFXIV_Lodestone_SSF.ttf') format('truetype');
|
||||
src: url('/files/FFXIV_Lodestone_SSF.ttf') format('truetype');
|
||||
unicode-range: U+E020-E0DB;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
font-family: 'Inter var';
|
||||
font-weight: 100 900;
|
||||
font-style: oblique 0deg 10deg;
|
||||
src: url('static/Inter.var.woff2') format('woff2');
|
||||
src: url('Inter.var.woff2') format('woff2');
|
||||
}
|
||||
|
||||
/* variables */
|
||||
|
||||
@@ -1,31 +1,20 @@
|
||||
// websocket connection
|
||||
class WSConnection {
|
||||
class SSEConnection {
|
||||
constructor() {
|
||||
this.socket = new WebSocket('ws://192.168.2.106:9001/ws');
|
||||
this.socket.addEventListener('open', this.onWSOpen.bind(this));
|
||||
this.socket.addEventListener('close', this.onWSClose.bind(this));
|
||||
this.socket.addEventListener('message', this.onWSMessage.bind(this));
|
||||
}
|
||||
this.socket = new EventSource('/sse', );
|
||||
|
||||
onWSOpen() {
|
||||
// send request for initial data (channels, currently selected channel)
|
||||
}
|
||||
this.socket.addEventListener('close', (e) => {
|
||||
console.log("Closing SSE connection.")
|
||||
this.socket.close()
|
||||
});
|
||||
|
||||
onWSClose() {
|
||||
// open new websocket here? for mobile
|
||||
}
|
||||
|
||||
onWSMessage(event) {
|
||||
try {
|
||||
this.socket.onmessage = (event) => {
|
||||
let eventData = JSON.parse(event.data);
|
||||
for (let message of eventData.messages)
|
||||
{
|
||||
addMessage(message);
|
||||
}
|
||||
} catch (error) {
|
||||
// TODO: error handling?
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
send(message) {
|
||||
@@ -33,7 +22,7 @@ class WSConnection {
|
||||
}
|
||||
}
|
||||
|
||||
const ws = new WSConnection();
|
||||
const sse = new SSEConnection();
|
||||
|
||||
|
||||
// channel switcher
|
||||
|
||||
Reference in New Issue
Block a user