mirror of
https://github.com/LukeHagar/crossws.git
synced 2025-12-10 12:27:46 +00:00
feat: universal access to all peers (#60)
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user