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

long polling - how it works? #2

Closed
andyrichter opened this issue Dec 28, 2021 · 7 comments
Closed

long polling - how it works? #2

andyrichter opened this issue Dec 28, 2021 · 7 comments

Comments

@andyrichter
Copy link

Hello Rob
i would like to control my bluesound device via javascript. Can you explain to me how to implement "long polling"?
Thank You

@roblans
Copy link
Owner

roblans commented Dec 28, 2021

Hi Andy,

  1. A request is sent to the server.
  2. The server doesn’t close the connection until it has a message to send.
  3. When a message appears – the server responds to the request with it.
  4. The client makes a new request immediately.

for more information: https://javascript.info/long-polling

@andyrichter
Copy link
Author

andyrichter commented Dec 28, 2021 via email

@kjavia
Copy link

kjavia commented Sep 30, 2022

@roblans Excellent library. I was trying to replicate the official player in Ionic/React to run on my Android TV. However I ran into a problem. The BluSound player doesn't like a shorter retry interval when the client polls for the status. I had it every 1 second and I started seeing connection errors. I see you have the retry at 5 seconds. Which makes me think that their API is not really useful for a real time player.

@roblans
Copy link
Owner

roblans commented Sep 30, 2022

The retry of 5 seconds is only used to restore the connection in case of an error. Real time notifications are provided by the long-polling mechanism.

@kjavia
Copy link

kjavia commented Sep 30, 2022

When the player is playing then the web server returns the status and closes the connection. So I have to resend the request for a new status after 1 sec, this is where the problem is. If the player is paused then the long polling connection is kept open.

@roblans
Copy link
Owner

roblans commented Sep 30, 2022

When the player is playing then the web server returns the status and closes the connection

This is new to me, I'm using this library with 2 different BluOS players and have never encountered this.

@kjavia
Copy link

kjavia commented Oct 1, 2022

I am using React + Axios. Maybe that's the difference? I made some adjustments to prevent unnecessary rendering and now the long polling request just sits there while the player is playing. It only completes when the player pauses or changes tracks (I am using my phone to change the tracks etc.) I am passing the etag and timeout once I get it.

@roblans roblans closed this as completed Dec 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants