Closed robinmaree closed 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.
It seems the
socket.onDisconnect
callback function is called late. But we do see theServer unreachable from heartbeat
error message very quickly (setHeartbeatTimeoutMs = 3000ms) after disabling WiFi. I’ve debugged this a bit, it’s callingWebSocketAdapterText:close
, but takes some time before calling theWebSocketAdapterText.onClose
callback (which calls thesocket.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.