mirror of
https://github.com/nbd-wtf/nostr-tools.git
synced 2025-12-08 16:28:49 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06e867b675 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nostr-tools",
|
||||
"version": "0.8.1",
|
||||
"version": "0.9.0",
|
||||
"description": "Tools for making a Nostr client.",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
15
relay.js
15
relay.js
@@ -13,7 +13,7 @@ export function normalizeRelayURL(url) {
|
||||
export function relayConnect(url, onNotice) {
|
||||
url = normalizeRelayURL(url)
|
||||
|
||||
var ws, resolveOpen, untilOpen
|
||||
var ws, resolveOpen, untilOpen, wasClosed
|
||||
var openSubs = {}
|
||||
let attemptNumber = 1
|
||||
let nextAttemptSeconds = 1
|
||||
@@ -34,10 +34,13 @@ export function relayConnect(url, onNotice) {
|
||||
resolveOpen()
|
||||
|
||||
// restablish old subscriptions
|
||||
for (let channel in openSubs) {
|
||||
let filters = openSubs[channel]
|
||||
let cb = channels[channel]
|
||||
sub({cb, filter: filters}, channel)
|
||||
if (wasClosed) {
|
||||
wasClosed = false
|
||||
for (let channel in openSubs) {
|
||||
let filters = openSubs[channel]
|
||||
let cb = channels[channel]
|
||||
sub({cb, filter: filters}, channel)
|
||||
}
|
||||
}
|
||||
}
|
||||
ws.onerror = () => {
|
||||
@@ -58,6 +61,8 @@ export function relayConnect(url, onNotice) {
|
||||
connect()
|
||||
} catch (err) {}
|
||||
}, nextAttemptSeconds * 1000)
|
||||
|
||||
wasClosed = true
|
||||
}
|
||||
|
||||
ws.onmessage = async e => {
|
||||
|
||||
Reference in New Issue
Block a user