fix multi tab presence
This commit is contained in:
@@ -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",
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user