Giter Club home page Giter Club logo

Comments (2)

tsightler avatar tsightler commented on September 27, 2024

One step would be to use something way newer the 9.23.0, latest version is 13.1.0. Nothing that old has been tested in a very long time and there are many updates to token handling due to changes in Ring API. You will not have much success with such an old version.

Changes to the token while the connection is active should not matter, the token is automatically updated in-memory and you don't need to care about this. The consuming code must monitor onNewRefreshToken so that it can save these new tokens for a future new connection.

You didn't share your code, just some random logs that only you can understand (clearly not from ring-client-api). Attempting to interpret your logs in the absence of other information, it appears to show new connections, but it's not at all clear why you keep reconnecting to Ring. This is not required, once the API client is connected, you can just reuse the connection without concerning about the token.

Your example was this:

  • Create an API Client <-- Not sure how you are creating an API client without already having a token
  • npx -p ring-client-api ring-auth-cli
  • Subscribe to ring.onRefreshTokenUpdated and listen for any events
  • if event, update persistence with new token, delete old one.
  • Use auth token to call getCameras - get success
  • Use auth token to call getCameras - get Auth error

But to me the flow is more like this:

  • npx -p ring-client-api ring-auth-cli - get a token and store it in the persistent file
  • Create an API Client using token from persistent file
  • Subscribe to ring.onRefreshTokenUpdated and, on new event, replace the token in the persistent file
  • Use API client and getCameras - get success
  • Use API client and getCameras - get success

If at any point the connection is closed, create a new API Client using the last token saved in the persistent file, that is all.

A new token will be generated every time you make a new connection, but that should not matter as you should only need to make a new connection if the prior code has existed.

from ring.

dannyb648 avatar dannyb648 commented on September 27, 2024

@tsightler Thanks for your feedback and insight

You were right, the issue was I was creating a new ring client for each request. I guess this isn't the correct pattern. I'll raise a PR with a note for the Wiki to make this more explicit.

The fix for me was to add a new InitRing function which called the RingAPI class at start up and then a getter for whenever I actually wanted to use it.

Didn't need to upgrade the version (although I will!)

Appreciate the help!

from ring.

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.