@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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/monitor.ts +26 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ascegu/teamily",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "OpenClaw Teamily channel plugin - Team instant messaging server integration",
5
5
  "type": "module",
6
6
  "main": "index.ts",
package/src/monitor.ts CHANGED
@@ -80,8 +80,17 @@ export class TeamilyMonitor {
80
80
  }
81
81
 
82
82
  if (this.ws) {
83
- this.ws.close(1000, "Monitoring stopped");
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
- // Close the connection so it can be re-established
210
- if (this.ws) {
211
- this.ws.close();
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