Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get progress events from Fetch #1504

Closed
joeyparrish opened this issue Jul 23, 2018 · 2 comments
Closed

Get progress events from Fetch #1504

joeyparrish opened this issue Jul 23, 2018 · 2 comments
Assignees
Labels
status: archived Archived and locked; will not be updated type: enhancement New feature or request
Milestone

Comments

@joeyparrish
Copy link
Member

Split off from #1051:

We need progress events from Fetch so that after #1051, we don't have to prefer XHR again.

@joeyparrish joeyparrish added the type: enhancement New feature or request label Jul 23, 2018
@joeyparrish joeyparrish added this to the Backlog milestone Jul 23, 2018
@rounce
Copy link

rounce commented Aug 2, 2018

I did it this way:

let fetch = shaka.net.HttpFetchPlugin.fetch_;
  let promise = fetch(uri, init).then(function(response) {
    clearTimeout(timeout);
  
    let headers = {};
    /** @type {Headers} */
    let responseHeaders = response.headers;
    responseHeaders.forEach(function(value, key) {
      // Since IE/Edge incorrectly return the header with a leading new line
      // character ('\n'), we trim the header here.
      headers[key.trim()] = value;
    });
      
    const reader = response.body.getReader();
    let loaded = 0;
    return new ReadableStream({
      start(controller) {
        reader.read().then(function processData(result) {
          if (result.done) {
            controller.close();
            return;
          }
          controller.enqueue(result.value);
          loaded += result.value.byteLength;
          // progress = loaded / sizeTotal
          return reader.read().then(processData);
        });
      }
    });
  })
  .then((stream) => new Response(stream))
  .then((response) => {
    return response.arrayBuffer().then(function(arrayBuffer) {
      return shaka.net.HttpPluginUtils.makeResponse(headers,
          arrayBuffer, response.status, uri, response.url, requestType);
    });
  })
  .catch(function(error) {
...

@joeyparrish joeyparrish modified the milestones: Backlog, v2.5 Sep 27, 2018
@joeyparrish
Copy link
Member Author

Released in v2.5.0-beta2.

@shaka-project shaka-project locked and limited conversation to collaborators Nov 24, 2018
@shaka-bot shaka-bot added the status: archived Archived and locked; will not be updated label Apr 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: archived Archived and locked; will not be updated type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants