@iam4x/reconnecting-websocket 1.3.0 → 1.4.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.
- package/dist/index.js +20 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -180,9 +180,28 @@ export class ReconnectingWebSocket {
|
|
|
180
180
|
if (this.forcedClose) {
|
|
181
181
|
return;
|
|
182
182
|
}
|
|
183
|
-
//
|
|
183
|
+
// Proactively trigger reconnection due to inactivity
|
|
184
|
+
// Don't rely on the close event as it may never fire on a stalled connection
|
|
184
185
|
if (this.ws) {
|
|
186
|
+
// Stop health check to prevent it from also triggering reconnection
|
|
187
|
+
this.stopHealthCheck();
|
|
188
|
+
// Remove event listeners to prevent any late events from interfering
|
|
189
|
+
if (this.openFn)
|
|
190
|
+
this.ws.removeEventListener("open", this.openFn);
|
|
191
|
+
if (this.msgFn)
|
|
192
|
+
this.ws.removeEventListener("message", this.msgFn);
|
|
193
|
+
if (this.closeFn)
|
|
194
|
+
this.ws.removeEventListener("close", this.closeFn);
|
|
195
|
+
if (this.errorFn)
|
|
196
|
+
this.ws.removeEventListener("error", this.errorFn);
|
|
197
|
+
// Try to close the socket (may hang on stalled connections, but we don't wait)
|
|
185
198
|
this.ws.close();
|
|
199
|
+
// Clear the socket reference
|
|
200
|
+
this.ws = undefined;
|
|
201
|
+
// Emit close event to listeners with a special code indicating inactivity timeout
|
|
202
|
+
this.emit("close", { code: 4000, reason: "Inactivity timeout" });
|
|
203
|
+
// Schedule reconnection directly without waiting for close event
|
|
204
|
+
this.scheduleReconnect();
|
|
186
205
|
}
|
|
187
206
|
}, this.options.watchingInactivityTimeout);
|
|
188
207
|
}
|