ditto/src/pool.ts

27 lines
878 B
TypeScript
Raw Normal View History

import { getActiveRelays } from '@/db/relays.ts';
import { Debug, type Event, RelayPoolWorker } from '@/deps.ts';
2023-12-28 01:48:48 +00:00
const debug = Debug('ditto:pool');
const activeRelays = await getActiveRelays();
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, {
// The pipeline verifies events.
skipVerification: true,
// The logging feature overwhelms the CPU and creates too many logs.
logErrorsAndNotices: false,
});
/** Publish an event to the given relays, or the entire pool. */
function publish(event: Event, relays: string[] = activeRelays) {
2023-12-28 01:48:48 +00:00
debug('publish', event);
return pool.publish(event, relays);
}
export { activeRelays, pool, publish };