-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
75 lines (61 loc) · 1.8 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import 'websocket-polyfill'
import pkg from 'nostr-tools'
const relayInit = pkg.relayInit
let pk = 'YOUR_HEX_ENCODED_PUBLIC_KEY_HERE'
const relayFromUrls = [
'wss://no.str.cr',
'wss://paid.no.str.cr',
'wss://nostr.fly.dev',
'wss://relay.snort.social',
'wss://relay.realsearch.cc',
'wss://relay.nostrgraph.net',
'wss://relay.minds.com/nostr/v1/ws',
'wss://nos.lol',
'wss://relay.current.fyi',
'wss://puravida.nostr.land',
'wss://nostr.milou.lol',
'wss://eden.nostr.land',
'wss://relay.damus.io',
'wss://nostr.oxtr.dev',
]
const relayToUrl = 'TO_RELAY_URL'
const eventsReceived = []
relayFromUrls.forEach(async (relayUrl) => {
const relayFrom = relayInit(relayUrl)
await relayFrom.connect()
const relayTo = relayInit(relayToUrl)
await relayTo.connect()
const eventsToMove = []
relayFrom.on('connect', () => {
console.log(`connected to ${relayFrom.url}`)
})
relayTo.on('connect', () => {
console.log(`connected to ${relayTo.url}`)
})
const sub = relayFrom.sub([
{
authors: [pk],
}
])
sub.on('event', event => {
if(eventsReceived.indexOf(event.id) === -1) {
eventsToMove.push(event)
eventsReceived.push(event.id)
}
})
sub.on('eose', async () => {
sub.unsub()
console.log(`got ${eventsToMove.length} events from ${relayFrom.url}`)
eventsToMove.forEach(async (event, index) => {
const pub = relayTo.publish(event)
pub.on('ok', async () => {
console.log(`${relayTo.url} has accepted our event from ${relayFrom.url} on ${new Date(event.created_at * 1000).toISOString()} of kind ${event.kind} and ID ${event.id}`)
if(index == eventsToMove.length - 1) {
console.log(`done with ${relayFrom.url}`)
await relayFrom.close()
await relayTo.close()
}
})
})
})
})