diff --git a/site/static/app.js b/site/static/app.js index 2d17533..02e0a50 100644 --- a/site/static/app.js +++ b/site/static/app.js @@ -209,43 +209,27 @@ function uploadFileWS(url, f, idx) { ws.binaryType = 'arraybuffer'; ws.onopen = function () { - ws.bufferedAmountLowThreshold = CHUNK; var reader = new FileReader(); - - function sendNext() { - var end = Math.min(offset + CHUNK, f.size); - reader.readAsArrayBuffer(f.file.slice(offset, end)); - } - reader.onload = function (e) { ws.send(e.target.result); offset += CHUNK; - - var pct = Math.round(offset / f.size * 100); - if (pct - lastProgress >= 5) { - lastProgress = pct; - f.progress = pct; - renderTable(); - } - - if (offset >= f.size) { - // Когда буфер опустеет — шлём DONE - function checkDone() { - if (ws.bufferedAmount === 0) { - ws.send('DONE'); - } else { - setTimeout(checkDone, 50); - } + if (offset < f.size) { + var pct = Math.round(offset / f.size * 100); + if (pct - lastProgress >= 10) { + lastProgress = pct; + f.progress = pct; + renderTable(); } - checkDone(); + readNext(); + } else { + ws.send('DONE'); } }; - - ws.addEventListener('bufferedamountlow', function () { - if (offset < f.size) sendNext(); - }); - - sendNext(); + function readNext() { + var end = Math.min(offset + CHUNK, f.size); + reader.readAsArrayBuffer(f.file.slice(offset, end)); + } + readNext(); }; ws.onmessage = function (e) {