diff --git a/html/ndt7-download.js b/html/ndt7-download.js
index 8ab956d9..f115e7e9 100644
--- a/html/ndt7-download.js
+++ b/html/ndt7-download.js
@@ -10,12 +10,12 @@ onmessage = function (ev) {
postMessage(null)
}
sock.onopen = function () {
- const start = new Date().getTime()
+ const start = performance.now()
let previous = start
let total = 0
sock.onmessage = function (ev) {
total += (ev.data instanceof Blob) ? ev.data.size : ev.data.length
- let now = new Date().getTime()
+ let now = performance.now()
const every = 250 // ms
if (now - previous > every) {
postMessage({
diff --git a/html/ndt7-upload.js b/html/ndt7-upload.js
index aa23030f..a24975ff 100644
--- a/html/ndt7-upload.js
+++ b/html/ndt7-upload.js
@@ -11,8 +11,9 @@ onmessage = function (ev) {
postMessage(null)
}
function uploader(socket, data, start, previous, total) {
- let now = new Date().getTime()
+ let now = performance.now()
const duration = 10000 // millisecond
+ const every = 250 // millisecond
if (now - start > duration) {
sock.close()
return
@@ -22,11 +23,15 @@ onmessage = function (ev) {
data = new Uint8Array(data.length * 2) // TODO(bassosimone): fill this message
}
const underbuffered = 7 * data.length
- while (sock.bufferedAmount < underbuffered) {
+ while ((sock.bufferedAmount < underbuffered) &&
+ (performance.now() - previous < every)) {
sock.send(data)
total += data.length
+ if (data.length < maxMessageSize && data.length < (total - sock.bufferedAmount)/16) {
+ break
+ }
}
- const every = 250 // millisecond
+ now = performance.now()
if (now - previous > every) {
postMessage({
'AppInfo': {
@@ -42,11 +47,19 @@ onmessage = function (ev) {
function() { uploader(sock, data, start, previous, total) },
0)
}
+ sock.onmessage = function (ev) {
+ if (!(ev.data instanceof Blob)) {
+ let m = JSON.parse(ev.data)
+ m.Origin = 'server'
+ m.Test = 'upload'
+ postMessage(m)
+ }
+ }
sock.onopen = function () {
const initialMessageSize = 8192 /* (1<<13) */
const data = new Uint8Array(initialMessageSize) // TODO(bassosimone): fill this message
sock.binarytype = 'arraybuffer'
- const start = new Date().getTime()
+ const start = performance.now()
uploader(sock, data, start, start, 0)
}
}