fix: attempt to stop spamming websocket

socket needs major fixes because of weird tokio stuff
This commit is contained in:
trisua 2025-04-28 01:30:03 -04:00
parent 93c4093620
commit 3a12c0ee6c
3 changed files with 41 additions and 21 deletions

View file

@ -442,12 +442,6 @@
{% if selected_channel %}
<script>
if (window.socket) {
window.socket.close();
window.socket = undefined;
console.log("closed old");
}
setTimeout(() => {
if (window.socket) {
if (window.socket_id === "{{ selected_channel }}") {
@ -460,6 +454,18 @@
}
}
for (const anchor of document.querySelectorAll("a")) {
if (anchor.href.includes("{{ selected_channel }}")) {
continue;
}
anchor.addEventListener("click", () => {
window.socket.close();
window.socket = undefined;
console.log("force abandon socket");
});
}
const endpoint = `${window.location.origin.replace("http", "ws")}/api/v1/channels/{{ selected_channel }}/ws`;
const socket = new WebSocket(endpoint);
window.socket = socket;