diff options
author | Andrew Cady <d@jerkface.net> | 2023-01-31 23:12:34 -0500 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2023-01-31 23:12:34 -0500 |
commit | cc24253726bcea8b51d2cdf3d7a3f65bf34270d9 (patch) | |
tree | 4ddcfb6ee95ccdaf7e55009defa3deec305886e9 | |
parent | 9ab764d1029692476128aec94b537091b6c06d41 (diff) |
try to resend blobs after network failures
-rw-r--r-- | vmail/htdocs/index.html | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/vmail/htdocs/index.html b/vmail/htdocs/index.html index 0fb49af..75706b0 100644 --- a/vmail/htdocs/index.html +++ b/vmail/htdocs/index.html | |||
@@ -44,6 +44,7 @@ | |||
44 | <button id="btn-start-recording" disabled>Record</button> | 44 | <button id="btn-start-recording" disabled>Record</button> |
45 | <button id="btn-stop-recording" disabled>Stop</button> | 45 | <button id="btn-stop-recording" disabled>Stop</button> |
46 | <button id="btn-save-recording" disabled>Save</button> | 46 | <button id="btn-save-recording" disabled>Save</button> |
47 | <div><span id="showBlobsSent" ></span></div> | ||
47 | 48 | ||
48 | <hr> | 49 | <hr> |
49 | <video controls style="height: 480px; width: 640px;" muted></video> | 50 | <video controls style="height: 480px; width: 640px;" muted></video> |
@@ -224,6 +225,23 @@ function getFileName(n) | |||
224 | return fileBaseName + ".part" + n + ".webm" | 225 | return fileBaseName + ".part" + n + ".webm" |
225 | } | 226 | } |
226 | 227 | ||
228 | var blobsSent = 0; | ||
229 | var blobsQueued = 0; | ||
230 | var blobsFailed = 0; | ||
231 | var blobQueue = new Array(); | ||
232 | resetTimeout() | ||
233 | { | ||
234 | setTimeout(function () | ||
235 | { | ||
236 | while (blobQueue.length) (blobQueue.shift())(); | ||
237 | resetTimeout(); | ||
238 | }, 100); | ||
239 | } | ||
240 | resetTimeout(); | ||
241 | function resendBlob(blob, idx) | ||
242 | { | ||
243 | blobQueue.push(function () { return sendBlob(blob, idx); }); | ||
244 | } | ||
227 | function sendBlob(blob, idx) | 245 | function sendBlob(blob, idx) |
228 | { | 246 | { |
229 | var fileObject = new File([blob], getFileName(idx), { | 247 | var fileObject = new File([blob], getFileName(idx), { |
@@ -233,9 +251,16 @@ function sendBlob(blob, idx) | |||
233 | formData.append('video-sequence-number', idx); | 251 | formData.append('video-sequence-number', idx); |
234 | formData.append('video-blob', fileObject); | 252 | formData.append('video-blob', fileObject); |
235 | 253 | ||
236 | var onSuccess = function () { return; } | 254 | var onSuccess = function() { |
237 | var onError = function () { return; } | 255 | blobsSent++; |
256 | } | ||
257 | var onError = function(code) { | ||
258 | if (code >= 500) blobsFailed++; | ||
259 | else resendBlob(blob, idx); | ||
260 | return; | ||
261 | } | ||
238 | postMessageByUuidBlob(fileBaseName, formData, onSuccess, onError); | 262 | postMessageByUuidBlob(fileBaseName, formData, onSuccess, onError); |
263 | blobsQueued++; | ||
239 | } | 264 | } |
240 | 265 | ||
241 | var audioCtx = new (window.AudioContext || webkitAudioContext)(); | 266 | var audioCtx = new (window.AudioContext || webkitAudioContext)(); |