Skip to content

Commit

Permalink
fix: Fix numBytesRemaining when the request is done (#6653)
Browse files Browse the repository at this point in the history
  • Loading branch information
avelad authored and joeyparrish committed May 31, 2024
1 parent 45438d9 commit 7f75320
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/net/http_fetch_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,10 @@ shaka.net.HttpFetchPlugin = class {
// is long enough, or if a whole segment is downloaded, call
// progressUpdated().
if (currentTime - lastTime > 100 || readObj.done) {
const numBytesRemaining =
readObj.done ? 0 : contentLength - loaded;
progressUpdated(currentTime - lastTime, loaded - lastLoaded,
contentLength - loaded);
numBytesRemaining);
lastLoaded = loaded;
lastTime = currentTime;
}
Expand Down
7 changes: 6 additions & 1 deletion lib/net/http_xhr_plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ shaka.net.HttpXHRPlugin = class {
const xhrResponse = xhr.response;

try {
const currentTime = Date.now();
progressUpdated(currentTime - lastTime, event.loaded - lastLoaded,
/* numBytesRemaining= */ 0);
const response = shaka.net.HttpPluginUtils.makeResponse(headers,
xhrResponse, xhr.status, uri, xhr.responseURL, requestType);
resolve(response);
Expand Down Expand Up @@ -97,8 +100,10 @@ shaka.net.HttpXHRPlugin = class {
// progressUpdated().
if (currentTime - lastTime > 100 ||
(event.lengthComputable && event.loaded == event.total)) {
const numBytesRemaining =
xhr.readyState == 4 ? 0 : event.total - event.loaded;
progressUpdated(currentTime - lastTime, event.loaded - lastLoaded,
event.total - event.loaded);
numBytesRemaining);
lastLoaded = event.loaded;
lastTime = currentTime;
}
Expand Down

0 comments on commit 7f75320

Please sign in to comment.