SE750-DART / nerds-oppose-society

Your favourite online game that coincidentally uses the writing from Cards Against Humanity®.
https://nos.alv.nz
Other
4 stars 4 forks source link

Refactor Socket.io frontend management #136

Closed taitfuller closed 2 years ago

taitfuller commented 2 years ago

The way we manage the Socket.io connection in the frontend can be improved.

Rationale

Currently, files import socket from src/socket.ts. I personally do not like this approach, as the socket connection is not always available as it is only established once a player joins a game, and thus a global export accessible to all components seems inappropriate.

Additionally NicknamePage currently establishes the actual connection to Socket.io. This seems quite smelly for a number of reasons. While we do want the connection to be established when the user joins through NicknamePage, we don't want to redirect them to NicknamePage in other circumstances, such as if they refresh their page after already connecting. This is the current behaviour as described in (#121) which is intentional until #101 is completed. However, we should look to refactor this now to initialise the connection in a place better than NicknamePage in preparation for #101's completion.

Proposed Changes

One thing to note with these changes is locating additional code within GameRouter. I believe after this issue is completed alongside #131 that GameRouter will be due for a refactor of its own. At this stage I am unsure of what form that will take, but will document the rational and proposal for changes in a seperate issue once I get a clearer picture.