From 9472d5eaa662a5b1eb534d01aca744c598769693 Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Wed, 27 Jun 2018 09:20:16 -0700 Subject: [PATCH] added delay when ws.bufferedAmount is high --- app/api.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/api.js b/app/api.js index 7ec1341e..f32b5abf 100644 --- a/app/api.js +++ b/app/api.js @@ -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);