Skip to content

Commit

Permalink
reference client fixes (#290)
Browse files Browse the repository at this point in the history
* reference client: fix issues with webkit browsers

webkit browsers tend to never leave the "sock.send()" loop. Make sure
they pause to post the AppInfo message. Change the timing to use
better source. Also exit the loop when it's time to increase the message size.

Co-authored-by: Peter Boothe <pboothe@google.com>
  • Loading branch information
aweits and pboothe authored Jun 16, 2020
1 parent 9536367 commit ce43f7a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions html/ndt7-download.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
21 changes: 17 additions & 4 deletions html/ndt7-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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': {
Expand All @@ -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)
}
}

0 comments on commit ce43f7a

Please sign in to comment.