Fix stupidity

This commit is contained in:
Schluffe
2026-09-17 22:21:02 +02:00
parent 6e867e33b1
commit f062753f8f
2 changed files with 47 additions and 22 deletions
+39 -19
View File
@@ -47,7 +47,7 @@ function flush(): Promise<void> {
} }
Deno.test( Deno.test(
"welcome all clients on open", "Welcome all clients on connect.",
setup(async () => { setup(async () => {
const [s1, m1] = await connect(href); const [s1, m1] = await connect(href);
const [s2, m2] = await connect(href); const [s2, m2] = await connect(href);
@@ -62,26 +62,46 @@ Deno.test(
}), }),
); );
// Deno.test( Deno.test(
// "removes a client from broadcast after it disconnects", "Messages all clients in a room on joining.",
// setup(async () => { setup(async () => {
// const [s1, m1] = await connect(href); const [s1, m1] = await connect(href);
// const [s2, m2] = await connect(href); const [s2, m2] = await connect(href);
// const [s3, m3] = await connect(href);
// await flush(); await flush();
m1.length = 0;
m2.length = 0;
// m1.length = 0; s1.send("/join meh");
// m2.length = 0; s2.send("/join meh");
// m3.length = 0; await flush();
// await close(s3); assertEquals(m1, ["1 has joined!", "2 has joined!"]);
assertEquals(m2, ["2 has joined!"]);
// assertEquals(m1, ["3 has left!"]); await close(s2);
// assertEquals(m2, ["3 has left!"]); await close(s1);
// assertEquals(m3, []); }),
);
// await close(s2); Deno.test(
// await close(s1); "Messages remaining members if one left the room.",
// }), setup(async () => {
// ); const [s1, m1] = await connect(href);
const [s2, m2] = await connect(href);
s1.send("/join meh");
s2.send("/join meh");
await flush();
m1.length = 0;
m2.length = 0;
await close(s2);
await flush();
assertEquals(m1, ["2 has left!"]);
assertEquals(m2, []);
await close(s1);
}),
);
+8 -3
View File
@@ -22,10 +22,15 @@ export function startServer(
}; };
const commands = { const commands = {
join: (id: number, ...args: string[]) => { join: (id: number, args: string[]) => {
const room = args[0]; const room = args[0];
roomsMap.getOrInsert(room, [id]); if (roomsMap.has(room)) {
clientRoomMap.getOrInsert(id, room); roomsMap.get(room)!.push(id);
} else {
roomsMap.set(room, [id]);
}
clientRoomMap.getOrInsert(id, room); // not sure about that
broadcast(room, `${id} has joined!`); broadcast(room, `${id} has joined!`);
}, },
} as const; } as const;