feat: universal access to all peers (#60)

This commit is contained in:
Pooya Parsa
2024-08-06 14:35:33 +02:00
committed by GitHub
parent bb4c9175e4
commit 7fa9976584
17 changed files with 256 additions and 84 deletions

View File

@@ -8,15 +8,24 @@ import { wsTests } from "./tests";
const fixtureDir = fileURLToPath(new URL("fixture", import.meta.url));
const websockets = new Set<WebSocket>();
afterEach(() => {
for (const ws of websockets) {
ws.close();
}
websockets.clear();
});
export function wsConnect(
url: string,
opts?: { skip?: number; headers?: OutgoingHttpHeaders },
) {
const ws = new WebSocket(url, { headers: opts?.headers });
websockets.add(ws);
const upgradeHeaders: Record<string, string> = Object.create(null);
const send = async (data: any) => {
const send = async (data: any): Promise<any> => {
ws.send(
typeof data === "string" ? data : JSON.stringify({ message: data }),
);
@@ -55,11 +64,6 @@ export function wsConnect(
}
});
afterEach(() => {
ws.removeAllListeners();
ws.close();
});
const res = {
ws,
send,