feat(transfers): websocket bağlantısı için dayanıklılık mekanizması ekle
WebSocket bağlantısı düştüğünde otomatik yeniden bağlanma ve geçici polling ile veri akışını sürdürme yeteneği eklendi. Bağlantı hatalarında konsola uyarı mesajı yazdırılır ve component kaldırıldığında timer'lar temizlenir.
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
let isAllPaused = false;
|
let isAllPaused = false;
|
||||||
let totalDownloaded = 0;
|
let totalDownloaded = 0;
|
||||||
let totalDownloadSpeed = 0;
|
let totalDownloadSpeed = 0;
|
||||||
|
let pollTimer;
|
||||||
|
|
||||||
// Modal / player state
|
// Modal / player state
|
||||||
let showModal = false;
|
let showModal = false;
|
||||||
@@ -27,6 +28,12 @@
|
|||||||
const token = getAccessToken();
|
const token = getAccessToken();
|
||||||
const url = `${API.replace("http", "ws")}?token=${token || ""}`;
|
const url = `${API.replace("http", "ws")}?token=${token || ""}`;
|
||||||
ws = new WebSocket(url);
|
ws = new WebSocket(url);
|
||||||
|
ws.onopen = () => {
|
||||||
|
if (pollTimer) {
|
||||||
|
clearInterval(pollTimer);
|
||||||
|
pollTimer = null;
|
||||||
|
}
|
||||||
|
};
|
||||||
ws.onmessage = (e) => {
|
ws.onmessage = (e) => {
|
||||||
const d = JSON.parse(e.data);
|
const d = JSON.parse(e.data);
|
||||||
if (d.type === "progress") {
|
if (d.type === "progress") {
|
||||||
@@ -37,6 +44,17 @@
|
|||||||
updateTransferStats();
|
updateTransferStats();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
ws.onerror = (err) => {
|
||||||
|
console.warn("WS hata:", err);
|
||||||
|
ws.close();
|
||||||
|
};
|
||||||
|
ws.onclose = () => {
|
||||||
|
// WS koptuğunda hafif bir polling ile listeyi güncel tut
|
||||||
|
if (!pollTimer) {
|
||||||
|
pollTimer = setInterval(list, 4000);
|
||||||
|
}
|
||||||
|
setTimeout(wsConnect, 2000);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async function list() {
|
async function list() {
|
||||||
@@ -449,7 +467,11 @@
|
|||||||
slider.style.setProperty("--fill", slider.value * 100);
|
slider.style.setProperty("--fill", slider.value * 100);
|
||||||
}
|
}
|
||||||
window.addEventListener("keydown", onEsc);
|
window.addEventListener("keydown", onEsc);
|
||||||
return () => window.removeEventListener("keydown", onEsc);
|
return () => {
|
||||||
|
window.removeEventListener("keydown", onEsc);
|
||||||
|
if (ws) ws.close();
|
||||||
|
if (pollTimer) clearInterval(pollTimer);
|
||||||
|
};
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user