nostr-tools 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/relay.js +10 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nostr-tools",
3
- "version": "0.8.1",
3
+ "version": "0.9.0",
4
4
  "description": "Tools for making a Nostr client.",
5
5
  "repository": {
6
6
  "type": "git",
package/relay.js CHANGED
@@ -13,7 +13,7 @@ export function normalizeRelayURL(url) {
13
13
  export function relayConnect(url, onNotice) {
14
14
  url = normalizeRelayURL(url)
15
15
 
16
- var ws, resolveOpen, untilOpen
16
+ var ws, resolveOpen, untilOpen, wasClosed
17
17
  var openSubs = {}
18
18
  let attemptNumber = 1
19
19
  let nextAttemptSeconds = 1
@@ -34,10 +34,13 @@ export function relayConnect(url, onNotice) {
34
34
  resolveOpen()
35
35
 
36
36
  // restablish old subscriptions
37
- for (let channel in openSubs) {
38
- let filters = openSubs[channel]
39
- let cb = channels[channel]
40
- sub({cb, filter: filters}, channel)
37
+ if (wasClosed) {
38
+ wasClosed = false
39
+ for (let channel in openSubs) {
40
+ let filters = openSubs[channel]
41
+ let cb = channels[channel]
42
+ sub({cb, filter: filters}, channel)
43
+ }
41
44
  }
42
45
  }
43
46
  ws.onerror = () => {
@@ -58,6 +61,8 @@ export function relayConnect(url, onNotice) {
58
61
  connect()
59
62
  } catch (err) {}
60
63
  }, nextAttemptSeconds * 1000)
64
+
65
+ wasClosed = true
61
66
  }
62
67
 
63
68
  ws.onmessage = async e => {