Compare commits

..

1 Commits

Author SHA1 Message Date
fiatjaf
22e895c7c2 use exponential backoff for reconnections. 2021-12-12 11:39:56 -03:00
2 changed files with 5 additions and 2 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "nostr-tools",
"version": "0.8.0",
"version": "0.8.1",
"description": "Tools for making a Nostr client.",
"repository": {
"type": "git",

View File

@@ -46,7 +46,10 @@ export function relayConnect(url, onNotice) {
ws.onclose = () => {
resetOpenState()
attemptNumber++
nextAttemptSeconds += attemptNumber
nextAttemptSeconds += attemptNumber ** 3
if (nextAttemptSeconds > 14400) {
nextAttemptSeconds = 14400 // 4 hours
}
console.log(
`relay ${url} connection closed. reconnecting in ${nextAttemptSeconds} seconds.`
)