Skip to content

Conversation

@Moondragon85
Copy link

Listen for a heartbeat in form of WebSocket Pings (see RFC 6455) and close the connection if none are received within a specified timeframe.

This solves the following problem:
If the network connection gets interrupted long enough the connection might time out on the server side but this module still shows the connection as active indefinitely. Which means in order to reconnect one has to manually disable and reenable the connection within Companion.
With this option enabled the connection will eventually time out on both sides and the module can automatically establish a new connection (if the reconnect option is enabled).

I made this function optional and the timeout configurable.
Apparently a common interval for sending those pings is 20 seconds (examples: WebSocket-Node, Python websockets) so 30 seconds seem like a reasonable default.

The timeout starts only after the first ping is received so if a server doesn't send any pings the connection will not get closed even if the option is enabled. However I still decided against enabling it by default because if a server does send pings but at an interval longer than specified (for example 60 seconds) the connection will close after the timeout despite having a stable network connection.

The implementation is based on the example code in Node.js WebSocket library.

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