As far as I know there is no way to get the exact time, but you can get an approximation.
Why you can't have an exact time ?
Most of the time is spent in the basecamp
servers, not in the request. The link you posted offers a way for basecamp
to push progress messages. If they don't do so, you will get nothing.
You can imagine the basecamp
servers as a wall. Behind the wall is the progress, but you can't see behind a wall and you are not allowed by basecamp
to climb it.
What to do ?
You can approximate this time. With a method similar to what is posted here:
var ajaxTime= new Date().getTime();
$.ajax({
type: "POST",
url: "some.php",
}).done(function () {
var totalTime = new Date().getTime()-ajaxTime;
});
you can measure how long it will take to complete a request.
Than you calculate the mean time
of all requests made to an url
. That time will be good enough.
I recommend something like this:
- Measure times by yourself for every request, 10 times.
- Calculate the mean of the times ( sum them and divide by 10 (the number of requests))
- Save the result and send it when you initiate your application and store in the browser.
- When user makes request, get the precalculated time and display a timer.
Update
To display a fix amount of time as a percent you can do like this:
-
secondsPerPercent = timeInSeconds / 100
<-- this is how many seconds need to pass for a percent to be filled.
- make a javascript timer (code for it can be found on google) that updates the percent every
secondsPerPercent
.