@exodus/ethereum-api 2.7.0 → 2.7.1
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.
- package/package.json +1 -1
- package/src/exodus-eth-server/ws.js +10 -1
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@ import WebSocket from '../websocket'
|
|
|
4
4
|
|
|
5
5
|
const RECONNECT_INTERVAL = ms('10s')
|
|
6
6
|
const PING_INTERVAL = ms('10s')
|
|
7
|
+
const MAX_RECONNECT_DELAY = ms('15s')
|
|
7
8
|
|
|
8
9
|
export default function createWebSocket(getURL) {
|
|
9
10
|
const addresses = new Set()
|
|
@@ -57,7 +58,9 @@ export default function createWebSocket(getURL) {
|
|
|
57
58
|
ws = null
|
|
58
59
|
clearInterval(pingIntervalId)
|
|
59
60
|
pingIntervalId = null
|
|
60
|
-
if (opened)
|
|
61
|
+
if (opened) {
|
|
62
|
+
openTimeoutId = setTimeout(open, reconnectDelay())
|
|
63
|
+
}
|
|
61
64
|
events.emit('close')
|
|
62
65
|
}
|
|
63
66
|
}
|
|
@@ -78,6 +81,12 @@ export default function createWebSocket(getURL) {
|
|
|
78
81
|
events.emit('close')
|
|
79
82
|
}
|
|
80
83
|
|
|
84
|
+
function reconnectDelay() {
|
|
85
|
+
const min = RECONNECT_INTERVAL
|
|
86
|
+
const max = MAX_RECONNECT_DELAY
|
|
87
|
+
return Math.floor(Math.random() * (max - min + 1) + min)
|
|
88
|
+
}
|
|
89
|
+
|
|
81
90
|
function watch(address) {
|
|
82
91
|
if (addresses.has(address)) return
|
|
83
92
|
addresses.add(address)
|