2023-09-06 03:00:32 +00:00
|
|
|
import { getActiveRelays } from '@/db/relays.ts';
|
2023-12-17 20:55:59 +00:00
|
|
|
import { type Event, RelayPoolWorker } from '@/deps.ts';
|
2023-09-06 03:00:32 +00:00
|
|
|
|
2023-12-17 17:00:04 +00:00
|
|
|
const activeRelays = await getActiveRelays();
|
2023-12-04 22:49:54 +00:00
|
|
|
|
2023-12-17 17:00:04 +00:00
|
|
|
console.log(`pool: connecting to ${activeRelays.length} relays.`);
|
|
|
|
|
2023-12-17 20:55:59 +00:00
|
|
|
const worker = new Worker('https://unpkg.com/nostr-relaypool@0.6.30/lib/nostr-relaypool.worker.js', { type: 'module' });
|
|
|
|
|
|
|
|
// @ts-ignore Wrong types.
|
|
|
|
const pool = new RelayPoolWorker(worker, activeRelays, {
|
2023-12-04 22:49:54 +00:00
|
|
|
// The pipeline verifies events.
|
|
|
|
skipVerification: true,
|
|
|
|
// The logging feature overwhelms the CPU and creates too many logs.
|
|
|
|
logErrorsAndNotices: false,
|
|
|
|
});
|
2023-09-06 03:00:32 +00:00
|
|
|
|
|
|
|
/** Publish an event to the given relays, or the entire pool. */
|
2023-12-17 17:00:04 +00:00
|
|
|
function publish(event: Event, relays: string[] = activeRelays) {
|
2023-09-06 03:00:32 +00:00
|
|
|
return pool.publish(event, relays);
|
|
|
|
}
|
|
|
|
|
2023-12-17 17:00:04 +00:00
|
|
|
export { activeRelays, pool, publish };
|