2023-09-06 03:00:32 +00:00
|
|
|
import { getActiveRelays } from '@/db/relays.ts';
|
|
|
|
import { type Event, RelayPool } from '@/deps.ts';
|
|
|
|
|
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.`);
|
|
|
|
|
|
|
|
const pool = new RelayPool(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 };
|