@ascegu/teamily 1.0.5 → 1.0.6
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/monitor.ts +26 -4
package/package.json
CHANGED
package/src/monitor.ts
CHANGED
|
@@ -80,8 +80,17 @@ export class TeamilyMonitor {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
if (this.ws) {
|
|
83
|
-
this.ws
|
|
83
|
+
const ws = this.ws;
|
|
84
|
+
ws.onopen = null;
|
|
85
|
+
ws.onmessage = null;
|
|
86
|
+
ws.onerror = null;
|
|
87
|
+
ws.onclose = null;
|
|
84
88
|
this.ws = null;
|
|
89
|
+
try {
|
|
90
|
+
ws.close(1000, "Monitoring stopped");
|
|
91
|
+
} catch {
|
|
92
|
+
// Ignore – socket may already be closed.
|
|
93
|
+
}
|
|
85
94
|
}
|
|
86
95
|
|
|
87
96
|
this.setState("disconnected");
|
|
@@ -201,15 +210,28 @@ export class TeamilyMonitor {
|
|
|
201
210
|
|
|
202
211
|
/**
|
|
203
212
|
* Handle WebSocket error.
|
|
213
|
+
* Detaches event handlers before closing to prevent recursive calls
|
|
214
|
+
* (ws.close() on an errored socket can re-fire onerror → stack overflow).
|
|
204
215
|
*/
|
|
205
216
|
private handleError(error: unknown): void {
|
|
206
217
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
207
218
|
this.setState("error", errorMessage);
|
|
208
219
|
|
|
209
|
-
//
|
|
210
|
-
|
|
211
|
-
|
|
220
|
+
// Detach handlers and grab ref before nulling, so close() cannot recurse.
|
|
221
|
+
const ws = this.ws;
|
|
222
|
+
if (ws) {
|
|
223
|
+
ws.onopen = null;
|
|
224
|
+
ws.onmessage = null;
|
|
225
|
+
ws.onerror = null;
|
|
226
|
+
ws.onclose = null;
|
|
212
227
|
this.ws = null;
|
|
228
|
+
try {
|
|
229
|
+
ws.close();
|
|
230
|
+
} catch {
|
|
231
|
+
// Ignore – socket may already be closed/invalid.
|
|
232
|
+
}
|
|
233
|
+
// onclose was detached, so manually trigger reconnect logic.
|
|
234
|
+
this.handleClose();
|
|
213
235
|
}
|
|
214
236
|
}
|
|
215
237
|
|