[wip] added socket shape for join game + started working on front handling of game param in url

This commit is contained in:
bgoulard 2026-01-11 17:03:12 +01:00 committed by Nigel
parent a435afb48f
commit b862dc27f1
4 changed files with 60 additions and 9 deletions

View file

@ -7,7 +7,7 @@ import {
} from "@app/routing";
import authHtml from "./pong.html?raw";
import io from "socket.io-client";
import type { CSocket, GameMove, GameUpdate, TourInfo } from "./socket";
import { JoinRes, type CSocket, type GameMove, type GameUpdate, type TourInfo } from "./socket";
import { showError, showInfo, showSuccess } from "@app/toast";
import { getUser as getSelfUser, type User } from "@app/auth";
import { isNullish } from "@app/utils";
@ -79,12 +79,11 @@ function pongClient(
): RouteHandlerReturn {
setTitle("Pong Game Page");
const urlParams = new URLSearchParams(window.location.search);
const game_req_join = urlParams.get("game");
if (game_req_join) {
showError(
"currently not supporting the act of joining game (even as a spectator)",
);
}
let game_req_join = urlParams.get("game");
// todo:
// [ ] shape sock
// - [ ] joinGame (guid) -> ["ok"|"no, dont ever talk to my kid or me ever again you creep"];
// - [ ] launch newgame evt?
return {
html: authHtml,
@ -240,6 +239,30 @@ function pongClient(
// keys end
// ---
// ---
// join game
// ---
if (game_req_join != null) {
socket.emit('joinGame', game_req_join,
(res : JoinRes) => {
switch (res) {
case JoinRes.yes :
showInfo('JoinRes = yes');
break;
case JoinRes.no :
showInfo('JoinRes = no');
break;
default:
showError('JoinRes switch fail:' + res);
}
}
)
game_req_join = null;
}
// ---
// join game end
// ---
// ---
// position logic (client)
// ---

View file

@ -37,6 +37,12 @@ export type TourInfo = {
remainingMatches: number | null,
};
export enum JoinRes {
yes = 'yes',
no = 'dont ever talk to me or my kid ever again',
dev = 'yaaaaaaaaaaaaaaaaaaaaaaaa',
};
export interface ClientToServer {
enqueue: () => void;
dequeue: () => void;
@ -46,6 +52,8 @@ export interface ClientToServer {
connectedToGame: (gameId: string) => void;
localGame: () => void;
joinGame: (guid : string, ack:(result:JoinRes) => void) => void;
hello: () => void;
// TOURNAMENT