I realize this is common question and I have read the previous posts about it but they don’t quite answer what I’m wondering about.
If the player goes offline you can detect it by a try/catch on a nakama call, but my question is what would be the best approach after that. Here’s what I do now:
Try/catch to get any network error, whenever a nakama call is being made
Push a “connection error”-popup on player (potentially forcing the load screen), the player can press “Try again” to reconnect.
The reconnect will authenticate/restore the session and if the socket is reporting as disconnected it’ll connect the socket.
But that won’t really work as you can restore the session while being offline and the socket reports as connected even if you disconnect.
So a couple alternatives I’ve come up with would be to either do a new authentication call to catch it (so never restore after a network error), or do some Ping RPC call to catch it, and then once again show the popup.
session.Restore is just meant to reconstitute the JWT stored in the client’s cache into a human-readable object. It isn’t intended to detect whether the client has a connection with the server, or “refresh” the current session. In order to “refresh” the session (i.e., obtain a new JWT from the server), use Authenticate....
We’re going to be releasing a new version of the Unity library next week that automates this for you.
@nixarn We’ve just released the .NET client SDK update and the Unity client SDK package release will follow tomorrow. In the meantime have a look at the release notes for the .NET code as its where most of the changes come from and let me know if you have any questions.
This will now handle automated refreshing of sessions. Let’s see if this helps you and if you still hit issues or have questions we can revisit for sure.