added delay when ws.bufferedAmount is high

This commit is contained in:
Danny Coates 2018-06-27 09:20:16 -07:00
parent 126ea8c7e6
commit 9472d5eaa6
No known key found for this signature in database
GPG Key ID: 4C442633C62E00CB
1 changed files with 4 additions and 1 deletions

View File

@ -1,4 +1,4 @@
import { arrayToB64, b64ToArray } from './utils';
import { arrayToB64, b64ToArray, delay } from './utils';
function post(obj) {
return {
@ -162,6 +162,9 @@ async function upload(
onprogress([Math.min(streamInfo.fileSize, size), streamInfo.fileSize]);
size += streamInfo.recordSize;
state = await reader.read();
while (ws.bufferedAmount > streamInfo.recordSize * 2) {
await delay();
}
}
const footer = new Uint8Array([0]);
ws.send(footer);