mirror of
https://github.com/Dangoware/confetti-box.git
synced 2025-04-18 14:52:58 -05:00
Force the websocket to close on page unload
This commit is contained in:
parent
4426192700
commit
83237c5d5a
1 changed files with 6 additions and 0 deletions
|
@ -222,6 +222,12 @@ async function uploadFileWebsocket(file, duration, maxSize) {
|
|||
const socket = new WebSocket(new_uri);
|
||||
socket.binaryType = "arraybuffer";
|
||||
|
||||
// Ensure that the websocket gets closed if the page is unloaded
|
||||
window.onbeforeunload = function() {
|
||||
socket.onclose = function () {};
|
||||
socket.close();
|
||||
};
|
||||
|
||||
const chunkSize = 5_000_000;
|
||||
socket.addEventListener("open", (_event) => {
|
||||
for (let chunk_num = 0; chunk_num < Math.floor(file.size / chunkSize) + 1; chunk_num ++) {
|
||||
|
|
Loading…
Reference in a new issue