reachlo 1.4.2 → 1.4.4
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/README.md +4 -2
- package/index.d.ts +2 -0
- package/index.js +25 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -96,11 +96,13 @@ Deliver real-time metrics, alerts, and notifications at scale.
|
|
|
96
96
|
|
|
97
97
|
## Advanced Configuration
|
|
98
98
|
|
|
99
|
-
For
|
|
99
|
+
For custom deployments or to tune retry behavior:
|
|
100
100
|
|
|
101
101
|
```js
|
|
102
102
|
const client = new Reachlo('YOUR_API_KEY', {
|
|
103
|
-
url: 'wss://your-custom-backend.com'
|
|
103
|
+
url: 'wss://your-custom-backend.com', // custom backend URL
|
|
104
|
+
maxInitialRetries: 3, // retries before first successful connect (auth failures)
|
|
105
|
+
maxNetworkRetries: 50 // retries after a drop (network failures). 0 = unlimited
|
|
104
106
|
});
|
|
105
107
|
```
|
|
106
108
|
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -14,6 +14,8 @@ class Reachlo {
|
|
|
14
14
|
this.heartbeatInterval = options.heartbeatInterval || 20000;
|
|
15
15
|
this.reconnectBaseDelay = options.reconnectBaseDelay || 1000;
|
|
16
16
|
this.reconnectMaxDelay = options.reconnectMaxDelay || 30000;
|
|
17
|
+
this.maxInitialRetries = options.maxInitialRetries ?? 3; // never opened: give up fast
|
|
18
|
+
this.maxNetworkRetries = options.maxNetworkRetries ?? 50; // ~25 mins of attempts at max backoff
|
|
17
19
|
this.batchInterval = options.batchInterval || 0; // 0 = disabled
|
|
18
20
|
|
|
19
21
|
// Batch state
|
|
@@ -82,6 +84,7 @@ class Reachlo {
|
|
|
82
84
|
|
|
83
85
|
connect() {
|
|
84
86
|
this.shouldReconnect = true;
|
|
87
|
+
this._connectionEstablished = false;
|
|
85
88
|
return new Promise((resolve, reject) => {
|
|
86
89
|
if (this.reconnectTimer) clearTimeout(this.reconnectTimer);
|
|
87
90
|
|
|
@@ -95,6 +98,7 @@ class Reachlo {
|
|
|
95
98
|
this.socket = new WebSocket(this.url, protocols);
|
|
96
99
|
|
|
97
100
|
this.socket.onopen = () => {
|
|
101
|
+
this._connectionEstablished = true;
|
|
98
102
|
this._log("Reachlo: Connected");
|
|
99
103
|
this.reconnecting = false;
|
|
100
104
|
this._reconnectAttempt = 0; // Reset backoff on successful connect
|
|
@@ -126,6 +130,9 @@ class Reachlo {
|
|
|
126
130
|
};
|
|
127
131
|
|
|
128
132
|
this.socket.onclose = (event) => {
|
|
133
|
+
const connectionWasEstablished = this._connectionEstablished;
|
|
134
|
+
this._connectionEstablished = false;
|
|
135
|
+
|
|
129
136
|
this._log("Reachlo: Connection closed", event.code, event.reason);
|
|
130
137
|
this._stopHeartbeat();
|
|
131
138
|
|
|
@@ -153,6 +160,24 @@ class Reachlo {
|
|
|
153
160
|
}
|
|
154
161
|
|
|
155
162
|
if (this.shouldReconnect) {
|
|
163
|
+
if (!connectionWasEstablished) {
|
|
164
|
+
// Never connected — likely bad key, give up after maxInitialRetries
|
|
165
|
+
if (this.maxInitialRetries > 0 && this._reconnectAttempt >= this.maxInitialRetries) {
|
|
166
|
+
this._error("Reachlo: Could not establish connection. Check your API key.");
|
|
167
|
+
this.shouldReconnect = false;
|
|
168
|
+
this._emitLifecycle('error');
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
} else {
|
|
172
|
+
// Was connected before — genuine network issue
|
|
173
|
+
if (this.maxNetworkRetries > 0 && this._reconnectAttempt >= this.maxNetworkRetries) {
|
|
174
|
+
this._error("Reachlo: Network retry limit reached, giving up.");
|
|
175
|
+
this.shouldReconnect = false;
|
|
176
|
+
this._emitLifecycle('error');
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
156
181
|
if (!this.reconnecting) {
|
|
157
182
|
this.reconnecting = true;
|
|
158
183
|
this._emitLifecycle('reconnecting');
|
package/package.json
CHANGED