-
Notifications
You must be signed in to change notification settings - Fork 19
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
Make time duration since last server data available #76
base: main
Are you sure you want to change the base?
Make time duration since last server data available #76
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like this makes sense, is it possible to cover it with some test?
} | ||
|
||
/** | ||
* Get the time since since connection or last data received |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Get the time since since connection or last data received | |
* Get the time since connection or last data received |
Shouldn't the heartbeat functionality be built out instead and automatically disconnect if no heartbeat frame is received within the acceptable time frame? |
Good point, I'll work on a viable test.
At the time this was the simplest diff I could patch-in to do what I needed, while detecting disconnects and re-connecting continued to be handled within the app. My application code (in the browser) manages creating and disposing a timer that checks both for closed connections and missed heartbeats. If this timer was moved into the library, a more involved event model between the library and the application would need to be built out. The .NET client, for example, has an even more involved model of also reconnecting when disconnected, I don't think reconnecting within this library would work easily in my application's case. The application is connecting to RabbitMQ streams, so needs to update |
Did you perform any benchmarks with this? How expensive is The client might not need to reconnect automatically, but socket could be closed and |
1eaf4be
to
f38cc02
Compare
Sounds like that would address #95? |
f38cc02
to
c1a20b2
Compare
With my WebSocket connection, I needed the client to re-connect when the connection wasn't active anymore. Setting the
heartbeat
would ensure the server sent something at a regular interval, but the application had no way to know when the heartbeats were.This was the solution I came up with, on every received message, store the current
performance.now()
value, a monotonic millisecond timer. It had to be within this library, because the only message during the time period might be the heartbeat message. Then the application can check if it has been significantly greater than the heartbeat time since the last received message, and attempt to re-connect.