Giter VIP home page Giter VIP logo

Comments (8)

absidue avatar absidue commented on June 8, 2024 3

The application level redirects tutorial covers both the making of new requests and overwriting the response data, so the code snippet there is probably a good starting point for you: https://shaka-player-demo.appspot.com/docs/api/tutorial-application-level-redirects.html

from shaka-player.

joeyparrish avatar joeyparrish commented on June 8, 2024 1

Roughly, yes. But you will have to overwrite the fields of res in your snippet, rather than return a different object.

You want some of the details from this tutorial (overwriting part of the response):

https://shaka-player-demo.appspot.com/docs/api/tutorial-license-wrapping.html

And some of the details from this tutorial (sending a new async request from a filter):

https://shaka-player-demo.appspot.com/docs/api/tutorial-license-server-auth.html

This could probably use a new tutorial entry if we don't add an explicit API of some kind.

from shaka-player.

avelad avatar avelad commented on June 8, 2024

You can use something like:


player.getNetworkingEngine().registerRequestFilter(function(type, request, context) {
  // Only manipulate license responses for example
  if (type == shaka.net.NetworkingEngine.RequestType.LICENSE) {
    // Do something
  }
});

As such there is no retry event.

from shaka-player.

falk-stefan avatar falk-stefan commented on June 8, 2024

Thanks @avelad for the response.

Not sure if that'll do in my case, however. I am sending a Bearer <token> with the Authorization header. The server will respond with HTTP 401 and a code auth/token-expired - only then I know that the request failed and that I have to refresh the token.

from shaka-player.

joeyparrish avatar joeyparrish commented on June 8, 2024

You can register a response filter to intercept the HTTP 401. If you make the filter async, it can refresh the token, then replicate the original request with the new token, and finally insert the new response in place of the first one.

from shaka-player.

joeyparrish avatar joeyparrish commented on June 8, 2024

This seems common enough, so if you want to propose an API to simplify this process for users, I'd be happy to review it.

from shaka-player.

falk-stefan avatar falk-stefan commented on June 8, 2024

@joeyparrish thank you! :)

If I get that right then I should be able to do somethign like this:

player.getNetworkingEngine()?.registerResponseFilter(async (req, res) => {
  if (res.status === 401) {
    const error = JSON.parse(String(res.data)) as HTTPError;
    if (error.code === 'auth/token-expired') {
      // 1. Refresh token
      // 2. fetch(res.uri)
      // 3. return new response object
    }
  }
  return res;
});

from shaka-player.

falk-stefan avatar falk-stefan commented on June 8, 2024

Thanks a lot guys! With that I should be able to fix the issue! :)

from shaka-player.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.