heroiclabs / nakama-js

JavaScript client for Nakama server written in TypeScript.
https://heroiclabs.com/docs/nakama/client-libraries/javascript/
Apache License 2.0
182 stars 54 forks source link

Implemented `onheartbeattimeout` callback for ping/pong. #151

Closed robinmaree closed 1 year ago

robinmaree commented 1 year ago

It seems the socket.onDisconnect callback function is called late. But we do see the Server unreachable from heartbeat error message very quickly (setHeartbeatTimeoutMs = 3000ms) after disabling WiFi. I’ve debugged this a bit, it’s calling WebSocketAdapterText:close, but takes some time before calling the WebSocketAdapterText.onClose callback (which calls the socket.onDisconnect)

My idea is that the WebSocket.close function is taking a while before completing since it’s doing a closing handshake on the socket (see: WebSocket.close() - Web APIs | MDN).

This PR implements an additional callback onheartbeattimeout which will be called directly when the ping/pong failed. This way we can detect connection problems sooner and inform the players. We have conducted internal testing on this build and verified that it is functioning properly.

CLAassistant commented 1 year ago

CLA assistant check
All committers have signed the CLA.

robinmaree commented 1 year ago

@lugehorsam As per our discussion on the forum, please review this pull request and provide your feedback. Additionally, please let me know if you have any suggestions on achieving the same outcome without using an extra callback, to avoid any confusion for the developers.