Skip to content
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

ISSUE-12 Game lobby implemented #26

Merged
merged 1 commit into from
Jul 13, 2020
Merged

ISSUE-12 Game lobby implemented #26

merged 1 commit into from
Jul 13, 2020

Conversation

InsafKhamzin
Copy link
Contributor

@InsafKhamzin InsafKhamzin commented Jul 9, 2020

#12
The logic for inviting and joining users to the room is implemented.

Backend:

Game mongo model:
players - array of players, it has an email and status ('invited', 'joined') of the player.
status - the status of the game. Statuses are to be considered, but for now: 'new' (the game just created), 'ready-to-start' (players limit reached and host can press start), 'in-progress' (the players are playing), 'finished'

New API routes:
/game/create - creates a new Game and adds the creator (host) into the players array right away.
/game/:gameId/join - adds player to players array. If the player already was there, just updated status to 'joined'

Socket.io
BE-user-joined event - subscribes the player to the room. The room id is the actual Game id. After that emits the event FE-user-joined to the room passing player's email, so the other players in the room can be notified.
I had an issue with socket.io as follows: the users keep reconnecting after 30 seconds, so they lose the room id. Solved this by specifying ping policies: pingInterval: 5000, pingTimeout: 10000. So the client keeps pinging the server every 5 seconds to know if it is still alive. This solved the problem. More about the issue: link

Frontend

GameContext
Manages the game state. Maybe we should use it managing lobby only (like LobbyContext.js), and create a separate for the actual game. Otherwise, the file is gonna be big...

socket.js util - opens the WebSocket connection to the backend and can be used across the whole app.
GameContext has FE-user-joined event subscription. It changes the players array and pops up the notification that the player is joined.

@darrenMabbayad
Copy link
Collaborator

Overall, awesome PR. However, I do think that we could remove the authFetch utility in /client/utils since our api calls need to deal with things differently.

In terms of isolating logic and api calls between joining a game, managing the game logic, and handling webrtc signals, I do agree that we should keep those in separate files.

@InsafKhamzin InsafKhamzin self-assigned this Jul 10, 2020
@InsafKhamzin InsafKhamzin merged commit 676a8df into dev Jul 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants