Fix stupidity
This commit is contained in:
+39
-19
@@ -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
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user