Fix stupidity
This commit is contained in:
+39
-19
@@ -47,7 +47,7 @@ function flush(): Promise<void> {
|
||||
}
|
||||
|
||||
Deno.test(
|
||||
"welcome all clients on open",
|
||||
"Welcome all clients on connect.",
|
||||
setup(async () => {
|
||||
const [s1, m1] = await connect(href);
|
||||
const [s2, m2] = await connect(href);
|
||||
@@ -62,26 +62,46 @@ Deno.test(
|
||||
}),
|
||||
);
|
||||
|
||||
// Deno.test(
|
||||
// "removes a client from broadcast after it disconnects",
|
||||
// setup(async () => {
|
||||
// const [s1, m1] = await connect(href);
|
||||
// const [s2, m2] = await connect(href);
|
||||
// const [s3, m3] = await connect(href);
|
||||
Deno.test(
|
||||
"Messages all clients in a room on joining.",
|
||||
setup(async () => {
|
||||
const [s1, m1] = await connect(href);
|
||||
const [s2, m2] = await connect(href);
|
||||
|
||||
// await flush();
|
||||
await flush();
|
||||
m1.length = 0;
|
||||
m2.length = 0;
|
||||
|
||||
// m1.length = 0;
|
||||
// m2.length = 0;
|
||||
// m3.length = 0;
|
||||
s1.send("/join meh");
|
||||
s2.send("/join meh");
|
||||
await flush();
|
||||
|
||||
// await close(s3);
|
||||
assertEquals(m1, ["1 has joined!", "2 has joined!"]);
|
||||
assertEquals(m2, ["2 has joined!"]);
|
||||
|
||||
// assertEquals(m1, ["3 has left!"]);
|
||||
// assertEquals(m2, ["3 has left!"]);
|
||||
// assertEquals(m3, []);
|
||||
await close(s2);
|
||||
await close(s1);
|
||||
}),
|
||||
);
|
||||
|
||||
// await close(s2);
|
||||
// await close(s1);
|
||||
// }),
|
||||
// );
|
||||
Deno.test(
|
||||
"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
@@ -22,10 +22,15 @@ export function startServer(
|
||||
};
|
||||
|
||||
const commands = {
|
||||
join: (id: number, ...args: string[]) => {
|
||||
join: (id: number, args: string[]) => {
|
||||
const room = args[0];
|
||||
roomsMap.getOrInsert(room, [id]);
|
||||
clientRoomMap.getOrInsert(id, room);
|
||||
if (roomsMap.has(room)) {
|
||||
roomsMap.get(room)!.push(id);
|
||||
} else {
|
||||
roomsMap.set(room, [id]);
|
||||
}
|
||||
|
||||
clientRoomMap.getOrInsert(id, room); // not sure about that
|
||||
broadcast(room, `${id} has joined!`);
|
||||
},
|
||||
} as const;
|
||||
|
||||
Reference in New Issue
Block a user