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

feat: Separate heart beat interval and timeout #5984

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

satoren
Copy link

@satoren satoren commented Nov 25, 2024

In my environment (macOS, Chrome) when I switch WiFi, the websocket disconnect event does not occur, it is reconnected by heartbeat. This means that the connection will not be restored for up to one minute with a timeout of the same number of seconds as the interval, which is 30 seconds with the default setting.
However, to resolve this, I feel that heart beat messages at an interval of once every 5 seconds is too much.

At this time, since an online event is generated, I wanted to send a heartbeat triggered by this event to perform disconnect detection with a timeout period shorter than the time of the heartbeat interval.

It is intended to be used as follows. This is expected to reduce the time it takes for the connection to be restored.

const socket = new Socket("endpoint", { heartbeatTimeoutMs: 5000 })
socket.connect()
window.addEventListener('online', ()=> socket.sendHeartbeat())

Added comment to clarify that `sendHeartbeat` is not private for allows Heartbeat to be sent at any time
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

Successfully merging this pull request may close these issues.

1 participant