-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store users in session #231
Open
richpjames
wants to merge
5
commits into
main
Choose a base branch
from
store-users-in-session
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Commits on Sep 18, 2024
-
This will allow us to fetch the session later by accessing the socket.data object in the server or client. We no longer autoconnect but only connect once a user has submitted their name. This prevents users being added to the session before they have comitted to the game. This allows users to retain their gamestate if their connection drops for any reason. This is following the guidance outlined here: https://socket.io/get-started/private-messaging-part-1/ Co-authored-by: Ynda Jas <[email protected]> Co-authored-by: George Eaton <[email protected]> Co-authored-by: Liz Daly <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for e06d65e - Browse repository at this point
Copy the full SHA e06d65eView commit details -
We want this logic in two places - when a player clicks join game (listening to the 'players:post') event and when restoring session of a previously joined player. It makes sense to abstract it to a function. I think it would be good if we extracted all event handlers like this to improve readability.
rich committedSep 18, 2024 Configuration menu - View commit details
-
Copy full SHA for eef5d58 - Browse repository at this point
Copy the full SHA eef5d58View commit details -
This will be used to store sessions serverside. This could be replaced by something like Redis or SQLite in future but this class is good enough for now. We save the session on connection and disconnection so it should always be up to date
Configuration menu - View commit details
-
Copy full SHA for 0d1e018 - Browse repository at this point
Copy the full SHA 0d1e018View commit details -
We need a way for users to reconnect to their serverside session if their connection drops or they leave the page and return. We use sessionStorage so that the session is not shared across tabs as it would be for localStorage. We receive the "session:set" event from the server which tells us the server has save the session and now it's time for the client to do the same. We use the "DOMContentLoaded" event to attempt to read the sessionId from localStorage, if it exists then we connect. If it doesn't exist the user will have to manually connect by entering their name. Co-authored-by: Ynda Jas <[email protected]> Co-authored-by: George Eaton <[email protected]> Co-authored-by: Liz Daly <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for 6b3c533 - Browse repository at this point
Copy the full SHA 6b3c533View commit details -
Replace socketId with sessionId
Now we have a reliable way of tracking users we can use it across the app. Co-authored-by: Liz Daly <[email protected]> Co-authored-by: Rich James <[email protected]> Co-authored-by: George Eaton <[email protected]>
Configuration menu - View commit details
-
Copy full SHA for d4f38c7 - Browse repository at this point
Copy the full SHA d4f38c7View commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.