(args: {
id: number;
message?: {
type: "Text" | "Close";
data?: string;
};
})
| 7411 | } |
| 7412 | |
| 7413 | function sendToMockSocket(args: { |
| 7414 | id: number; |
| 7415 | message?: { |
| 7416 | type: "Text" | "Close"; |
| 7417 | data?: string; |
| 7418 | }; |
| 7419 | }) { |
| 7420 | const socket = mockSockets.get(args.id); |
| 7421 | if ( |
| 7422 | getConfig()?.mock?.stallWebsocketSends && |
| 7423 | args.message?.type !== "Close" |
| 7424 | ) { |
| 7425 | mockWebsocketSendMutexWedged = true; |
| 7426 | return new Promise<void>(() => {}); |
| 7427 | } |
| 7428 | |
| 7429 | if (!socket || !args.message) { |
| 7430 | return; |
| 7431 | } |
| 7432 | |
| 7433 | if (args.message.type === "Close") { |
| 7434 | mockSockets.delete(args.id); |
| 7435 | sendWsClose(socket.handler); |
| 7436 | return; |
| 7437 | } |
| 7438 | |
| 7439 | if (args.message.type !== "Text" || !args.message.data) { |
| 7440 | return; |
| 7441 | } |
| 7442 | |
| 7443 | const [type, ...rest] = JSON.parse(args.message.data) as [ |
| 7444 | string, |
| 7445 | ...unknown[], |
| 7446 | ]; |
| 7447 | |
| 7448 | if (type === "AUTH") { |
| 7449 | const event = rest[0] as RelayEvent; |
| 7450 | sendWsText(socket.handler, ["OK", event.id, true, ""]); |
| 7451 | return; |
| 7452 | } |
| 7453 | |
| 7454 | if (type === "REQ") { |
| 7455 | const subId = rest[0] as string; |
| 7456 | const filters = rest.slice(1) as MockFilter[]; |
| 7457 | if ( |
| 7458 | !filters.every((filter) => |
| 7459 | isPGatedFilterAuthorized(filter, MOCK_IDENTITY_PUBKEY), |
| 7460 | ) |
| 7461 | ) { |
| 7462 | sendWsText(socket.handler, ["CLOSED", subId, P_GATED_REJECTION_MESSAGE]); |
| 7463 | return; |
| 7464 | } |
| 7465 | |
| 7466 | if (subId.startsWith("live-")) { |
| 7467 | // Collect channel IDs from all filters in the REQ |
| 7468 | const channelIds = new Set<string>(); |
| 7469 | const kinds = new Set<number>(); |
| 7470 | for (const f of filters) { |
no test coverage detected