Compare commits

...

1 Commits

Author SHA1 Message Date
fiatjaf
06e867b675 stop sending repeated REQs. 2021-12-13 20:58:49 -03:00
2 changed files with 11 additions and 6 deletions

View File

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

View File

@@ -13,7 +13,7 @@ export function normalizeRelayURL(url) {
export function relayConnect(url, onNotice) { export function relayConnect(url, onNotice) {
url = normalizeRelayURL(url) url = normalizeRelayURL(url)
var ws, resolveOpen, untilOpen var ws, resolveOpen, untilOpen, wasClosed
var openSubs = {} var openSubs = {}
let attemptNumber = 1 let attemptNumber = 1
let nextAttemptSeconds = 1 let nextAttemptSeconds = 1
@@ -34,10 +34,13 @@ export function relayConnect(url, onNotice) {
resolveOpen() resolveOpen()
// restablish old subscriptions // restablish old subscriptions
for (let channel in openSubs) { if (wasClosed) {
let filters = openSubs[channel] wasClosed = false
let cb = channels[channel] for (let channel in openSubs) {
sub({cb, filter: filters}, channel) let filters = openSubs[channel]
let cb = channels[channel]
sub({cb, filter: filters}, channel)
}
} }
} }
ws.onerror = () => { ws.onerror = () => {
@@ -58,6 +61,8 @@ export function relayConnect(url, onNotice) {
connect() connect()
} catch (err) {} } catch (err) {}
}, nextAttemptSeconds * 1000) }, nextAttemptSeconds * 1000)
wasClosed = true
} }
ws.onmessage = async e => { ws.onmessage = async e => {