You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+31-1Lines changed: 31 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -133,14 +133,44 @@ import WebSocket from 'ws'
133
133
useWebSocketImplementation(WebSocket)
134
134
```
135
135
136
-
You can enable regular pings of connected relays with the `enablePing` option. This will set up a heartbeat that closes the websocket if it doesn't receive a response in time. Some platforms don't report websocket disconnections due to network issues, and enabling this can increase reliability.
136
+
#### enablePing
137
+
138
+
You can enable regular pings of connected relays with the `enablePing` option. This will set up a heartbeat that closes the websocket if it doesn't receive a response in time. Some platforms, like Node.js, don't report websocket disconnections due to network issues, and enabling this can increase the reliability of the `onclose` event.
137
139
138
140
```js
139
141
import { SimplePool } from'nostr-tools/pool'
140
142
141
143
constpool=newSimplePool({ enablePing:true })
142
144
```
143
145
146
+
#### enableReconnect
147
+
148
+
You can also enable automatic reconnection with the `enableReconnect` option. This will make the pool try to reconnect to relays with an exponential backoff delay if the connection is lost unexpectedly.
149
+
150
+
```js
151
+
import { SimplePool } from'nostr-tools/pool'
152
+
153
+
constpool=newSimplePool({ enableReconnect:true })
154
+
```
155
+
156
+
Using both `enablePing: true` and `enableReconnect: true` is recommended as it will improve the reliability and timeliness of the reconnection (at the expense of slighly higher bandwidth due to the ping messages).
The `enableReconnect` option can also be a callback function which will receive the current subscription filters and should return a new set of filters. This is useful if you want to modify the subscription on reconnect, for example, to update the `since` parameter to fetch only new events.
0 commit comments