revert: back to working simple send, bump to 1.0.16
Deploy loadtest / validate (push) Waiting to run
Deploy loadtest / validate (push) Waiting to run
This commit is contained in:
+14
-30
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user