Another step towards allowing users to reconnect to games. Users will now be able to refresh and see the same name as they had before, thanks to implementing some client-side persistence of socket.auth variables in local storage. Prior to this PR, we had stored them in local storage, but never used them.
In this PR:
When the game loads, the game reads the session ID from cache. It sends the socket the auth variables and tries to connect. If successful, the server emits a 'session' event that sets the username in redux, so that the client can display it / redirect to the main game page
When the user manually logs out, it clears both local storage AND fires off a disconnect event, resetting the server-side store
When the user refreshes / disconnects for any reason other than a manual log out, we don't disconnect them from the game.
Next up:
Right now the hierarchy of Room => Board is a flawed one. The issue is that players can disconnect from a game and not trigger the sequence of events to disconnect them from the board (that's ok, we want players to be able to rejoin their games), but we calculate the boards to send based on the rooms connected to various sockets in socket.io
We need to refactor do the following:
We need a separate manager, similar to SessionStore for managing rooms and boards. It could be called RoomStore, and it will include basic actions like joining a room, leaving a room, starting a game, etc. It should be able to access information via findSessions to get information such as connected, username, etc.
Migrate the game to using this store, starting with how we list our detailed rooms out
Example of being able to automatically log back in as an authenticated user:
Another step towards allowing users to reconnect to games. Users will now be able to refresh and see the same name as they had before, thanks to implementing some client-side persistence of socket.auth variables in local storage. Prior to this PR, we had stored them in local storage, but never used them.
In this PR:
Next up:
connected
, username, etc.Example of being able to automatically log back in as an authenticated user:
https://user-images.githubusercontent.com/1839462/226113332-caeecf4a-005f-4c4c-b3b3-7b5123daac2d.mov
Logging in automatically with last session as a guest user:
https://user-images.githubusercontent.com/1839462/226113362-80400399-87cc-4fc5-bdcc-1b4333c7701c.mov