-
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
Connection sequence #17
Comments
I'll add a design doc so we can discuss the overall flow before doing the breakdown. |
Modules would be based on domains. Participants and sessions consist a single domain, since participants only exist in context of a session. Modules consist of DAOs for data management, services implement business logic, and controllers expose these to external clients. |
Notes on authenticationTo simplify identity management, there will be only one endpoint for players: Having a single endpoint means that players can't open games in the wrong stage, and the frontend can render the appropriate UI for the current stage. When opening a game session ( at
If for whatever reason the page is reloaded:
This logic can be stashed away in a dedicated component, possibly called This also means that type DungeonAuthResult = {
session: Session;
localParticipantId: string;
socket: Socket;
};
class DungeonAuthenticator {
public async join(sessionId: string): Promise<DungeonAuthResult> {
const currentSessionId = localStorage.getItem('sessionId');
const participant = localStorage.getItem('participant') as Participant;
const authToken = localStorage.getItem('authToken');
if (currentSessionId == sessionId && authToken) {
// resume
// Grab participant data with auth token over HTTP
// Connect over WS
} else {
// join
// Request participant over HTTP
// Connect over WS
}
// Save auth token to LocalStorage
}
} The single play endpoint ( One possible way to force re-render is to use a dummy state: function useForce(): () => void {
const [_, setEmpty] = useState<object>({});
return () => setEmpty({});
}
export function PlayView(): JSX.Element {
const sessionId = useParams().id;
const dungeonClient = app.items.dungeonClient;
const rerender = useForce();
useEffect(() => {
dungeonClient.join(sessionId) // pls throw on fail
dungeonClient.onSessionStatus.add(() => rerender())
}, []);
return <>
{ dungeonClient.session.status == SessionStatus.IN_LOBBY && <ParticipantSetupView />}
</>;
} Note that when a client disconnects during lobby, the server can simply throw away that participant. When the client connects again, a new participant is created for it. Once the session is active and the game has started, participants are retained, even if the WebSocket connection is lost. Clients can resume using their auth token. Simply joining the session is disabled. |
Goals
Players can open the game view on their main screen. Upon loading, a new game session is created. The view displays a QR code that can be scanned, to join the game. A link is also provided.
The QR code / link brings players to an URL. Upon joining, the player joins the game session. The first joiner becomes the owner of the session.
All players can confirm their readiness. Once all players confirm, the game starts. Once the game has started, no more players can join.
The game session is thrown away when all players leave.
Out of scope
Breakdown
Depends on #13
Notes
The text was updated successfully, but these errors were encountered: