Updated home.js: Improved live upload speed

Forcefully wait for at least 1 second before calculating speed
Calculating faster tends to have 'jumpy' results
This commit is contained in:
Bobby Wibowo 2020-04-21 17:17:19 +07:00
parent 8932615fbb
commit f27db6f252
No known key found for this signature in database
GPG Key ID: 51C3A1E1E22D26CF
4 changed files with 11 additions and 9 deletions

2
dist/js/home.js vendored

File diff suppressed because one or more lines are too long

2
dist/js/home.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -389,12 +389,14 @@ page.prepareDropzone = () => {
if (!skipProgress) {
const now = Date.now()
const elapsedSecs = (now - xhr._upSpeedCalc.timestamp) / 1000
const bytesSent = upl.bytesSent - xhr._upSpeedCalc.bytes
bytesPerSec = elapsedSecs ? (bytesSent / elapsedSecs) : 0
// Update data for next upload speed calculation
xhr._upSpeedCalc.bytes = upl.bytesSent
xhr._upSpeedCalc.timestamp = now
// Calculate only if at least 1 second has elapsed
if (elapsedSecs >= 1) {
const bytesSent = upl.bytesSent - xhr._upSpeedCalc.bytes
bytesPerSec = elapsedSecs ? (bytesSent / elapsedSecs) : 0
// Update data for next upload speed calculation
xhr._upSpeedCalc.bytes = upl.bytesSent
xhr._upSpeedCalc.timestamp = now
}
}
file.previewElement.querySelector('.descriptive-progress').innerHTML =

View File

@ -1,5 +1,5 @@
{
"1": "1587463408",
"1": "1587464170",
"2": "1581416390",
"3": "1581416390",
"4": "1581416390",