nbd-wtf / nostr-tools

Tools for developing Nostr clients.
The Unlicense
685 stars 188 forks source link

How do I maintain a long link when using pool.subscribeMany? Currently, it will automatically disconnect after 2 minutes #396

Open jimtracy1007 opened 5 months ago

jimtracy1007 commented 5 months ago
`const relayConnect = async () => {
    pool.subscribeMany([...relays], [{
      kinds: [4],
      since: dayjs().unix(),
      authors: [subFrom],
      '#p': [p]
    }], {
      onevent: async (event) => {
        parseEvent(event)
      },
      onerror: async (err) => {
        console.log(err.message)
      },
      onclose: (reason) => {
        console.log(`relay connection closed at ${dayjs().format('YYYY-MM-DD HH:mm:ss')}:${reason}`);
        clearTimeout(timer);
        timer = setTimeout(async () => {
          relayConnect()
        }, 50);
      },
    })
  }

`relay connection closed at 2024-04-10 09:47:01:relay connection closed
relay connection closed at 2024-04-10 09:49:00:relay connection closed
relay connection closed at 2024-04-10 09:50:37:relay connection closed
relay connection closed at 2024-04-10 09:51:38:relay connection closed
relay connection closed at 2024-04-10 09:53:01:relay connection closed
relay connection closed at 2024-04-10 09:55:01:relay connection closed
relay connection closed at 2024-04-10 09:57:01:relay connection closed
relay connection closed at 2024-04-10 09:59:00:relay connection closed
relay connection closed at 2024-04-10 10:00:00:relay connection closed
relay connection closed at 2024-04-10 10:01:01:relay connection closed
relay connection closed at 2024-04-10 10:03:01:relay connection closed``
fiatjaf commented 4 months ago

Looks like the relay is closing the connection on you for some reason. What relay is it?

jimtracy1007 commented 4 months ago

wss://dev-relay.nostrassets.com, Do we need to pay attention to the configuration of the relay we built ourselves with?