@@ -1269,12 +1269,11 @@ OC.Uploader.prototype = _.extend({
12691269
12701270 if ( this . _supportAjaxUploadWithProgress ( ) ) {
12711271 //remaining time
1272- var lastUpdate = new Date ( ) . getMilliseconds ( ) ;
1273- var lastSize = 0 ;
12741272 var bufferSize = 20 ;
12751273 var buffer = [ ] ;
12761274 var bufferIndex = 0 ;
12771275 var bufferTotal = 0 ;
1276+ var filledBufferSize = 0 ;
12781277 for ( var i = 0 ; i < bufferSize ; i ++ ) {
12791278 buffer [ i ] = 0 ;
12801279 }
@@ -1308,19 +1307,19 @@ OC.Uploader.prototype = _.extend({
13081307 fileupload . on ( 'fileuploadprogressall' , function ( e , data ) {
13091308 self . log ( 'progress handle fileuploadprogressall' , e , data ) ;
13101309 var progress = ( data . loaded / data . total ) * 100 ;
1311- var thisUpdate = new Date ( ) . getMilliseconds ( ) ;
1312- var diffUpdate = ( thisUpdate - lastUpdate ) / 1000 ; // eg. 2s
1313- lastUpdate = thisUpdate ;
1314- var diffSize = data . loaded - lastSize ;
1315- lastSize = data . loaded ;
1316- diffSize = diffSize / diffUpdate ; // apply timing factor, eg. 1mb/2s = 0.5mb/s
1317- var remainingSeconds = ( ( data . total - data . loaded ) / diffSize ) ;
1310+ var remainingSeconds = ( ( data . total - data . loaded ) * 8 ) / data . bitrate ;
1311+
1312+ //Take the average remaining seconds of the last bufferSize events
1313+ //to prevent fluctuation and provide a smooth experience
13181314 if ( isFinite ( remainingSeconds ) && remainingSeconds >= 0 ) {
13191315 bufferTotal = bufferTotal - ( buffer [ bufferIndex ] ) + remainingSeconds ;
1320- buffer [ bufferIndex ] = remainingSeconds ; //buffer to make it smoother
1316+ buffer [ bufferIndex ] = remainingSeconds ;
13211317 bufferIndex = ( bufferIndex + 1 ) % bufferSize ;
1318+ if ( filledBufferSize < bufferSize ) {
1319+ filledBufferSize ++ ;
1320+ }
13221321 }
1323- var smoothRemainingSeconds = ( bufferTotal / bufferSize ) ; //seconds
1322+ var smoothRemainingSeconds = ( bufferTotal / filledBufferSize ) ;
13241323 var h = moment . duration ( smoothRemainingSeconds , "seconds" ) . humanize ( ) ;
13251324 self . $uploadprogressbar . attr ( 'data-loaded' , data . loaded ) ;
13261325 self . $uploadprogressbar . attr ( 'data-total' , data . total ) ;
0 commit comments