end to end!

This commit is contained in:
2025-08-23 20:32:50 -04:00
parent a2e8887a0b
commit 3347452ec4
12 changed files with 114 additions and 73 deletions

View File

@@ -62,31 +62,6 @@ const api = new Elysia({ prefix: "/api" })
)
.get("/games", () => [{ key: "simple", name: "simple" }])
.ws("/ws/:tableKey", {
response: WsOut,
body: WsIn,
message(
{
data: {
humanKey,
params: { tableKey },
},
},
body
) {
const {
inputs: { gameProposals, gameStarts, gameActions },
} = liveTable(tableKey);
if ("proposeGame" in body) {
gameProposals.emit(body);
} else if ("startGame" in body) {
gameStarts.emit(body);
} else if ("action" in body) {
gameActions.emit(body);
}
},
async open({
data: {
params: { tableKey },
@@ -108,6 +83,32 @@ const api = new Elysia({ prefix: "/api" })
);
table.inputs.presenceChanges.emit({ humanKey, presence: "joined" });
},
response: WsOut,
body: WsIn,
message(
{
data: {
humanKey,
params: { tableKey },
},
},
body
) {
const {
inputs: { gameProposals, gameStarts, gameActions },
} = liveTable(tableKey);
if ("proposeGame" in body) {
gameProposals.emit(body);
} else if ("startGame" in body) {
gameStarts.emit(body);
} else if ("action" in body) {
gameActions.emit({ humanKey, ...body.action });
}
},
async close({
data: {
params: { tableKey },