mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
34 lines
918 B
TypeScript
34 lines
918 B
TypeScript
import { RelayPoolWorker } from 'nostr-relaypool';
|
|
|
|
import { Storages } from '@/storages.ts';
|
|
import { Conf } from '@/config.ts';
|
|
|
|
const [relayList] = await Storages.db.query([
|
|
{ kinds: [10002], authors: [Conf.pubkey], limit: 1 },
|
|
]);
|
|
|
|
const tags = relayList?.tags ?? [];
|
|
|
|
const activeRelays = tags.reduce((acc, [name, url, marker]) => {
|
|
if (name === 'r' && !marker) {
|
|
acc.push(url);
|
|
}
|
|
return acc;
|
|
}, []);
|
|
|
|
console.log(`pool: connecting to ${activeRelays.length} relays.`);
|
|
|
|
const worker = new Worker('https://unpkg.com/nostr-relaypool2@0.6.34/lib/nostr-relaypool.worker.js', {
|
|
type: 'module',
|
|
});
|
|
|
|
// @ts-ignore Wrong types.
|
|
const pool = new RelayPoolWorker(worker, activeRelays, {
|
|
autoReconnect: true,
|
|
// The pipeline verifies events.
|
|
skipVerification: true,
|
|
// The logging feature overwhelms the CPU and creates too many logs.
|
|
logErrorsAndNotices: false,
|
|
});
|
|
|
|
export { activeRelays, pool };
|