Skip to content

Conversation

satoren
Copy link
Contributor

@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