fix multi tab presence

This commit is contained in:
2025-08-24 15:09:58 -04:00
parent 6c64886f2a
commit 4bcf071668
6 changed files with 59 additions and 18 deletions

View File

@@ -10,6 +10,7 @@ import dayjs from "dayjs";
import db from "./db";
import { liveTable, WsOut, WsIn } from "./table";
import { Human } from "@prisma/client";
import _ from "lodash";
const api = new Elysia({ prefix: "/api" })
.post("/whoami", async ({ cookie: { token } }) => {
@@ -74,9 +75,9 @@ const api = new Elysia({ prefix: "/api" })
}) {
const table = liveTable<SimpleGameState, SimpleAction>(tableKey);
table.outputs.playersPresent.onValue((players) =>
send({ players })
);
table.outputs.playersPresent
.skipDuplicates((p1, p2) => _.isEqual(new Set(p1), new Set(p2)))
.onValue((players) => send({ players }));
table.outputs.gameState.onValue((gameState) =>
send({
view:
@@ -84,7 +85,10 @@ const api = new Elysia({ prefix: "/api" })
getView(getKnowledge(gameState, humanKey), humanKey),
})
);
table.inputs.presenceChanges.emit({ humanKey, presence: "joined" });
table.inputs.connectionChanges.emit({
humanKey,
presence: "joined",
});
},
response: WsOut,
@@ -118,7 +122,7 @@ const api = new Elysia({ prefix: "/api" })
humanKey,
},
}) {
liveTable(tableKey).inputs.presenceChanges.emit({
liveTable(tableKey).inputs.connectionChanges.emit({
humanKey,
presence: "left",
});