@ynhcj/xiaoyi 0.0.1-beta → 0.0.3-beta
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/websocket.js +46 -2
- package/package.json +19 -14
package/dist/websocket.js
CHANGED
|
@@ -141,6 +141,18 @@ class XiaoYiWebSocketManager extends events_1.EventEmitter {
|
|
|
141
141
|
async connectToServer1() {
|
|
142
142
|
console.log(`[Server1] Connecting to ${this.config.wsUrl1}...`);
|
|
143
143
|
try {
|
|
144
|
+
// ✅ Close existing connection before creating new one to prevent ghost connections
|
|
145
|
+
if (this.ws1) {
|
|
146
|
+
console.log(`[Server1] Closing existing connection before reconnect`);
|
|
147
|
+
try {
|
|
148
|
+
this.ws1.removeAllListeners();
|
|
149
|
+
this.ws1.close();
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
console.warn(`[Server1] Error closing old connection:`, err);
|
|
153
|
+
}
|
|
154
|
+
this.ws1 = null;
|
|
155
|
+
}
|
|
144
156
|
const authHeaders = this.auth.generateAuthHeaders();
|
|
145
157
|
// Check if URL is wss + IP format, skip certificate verification
|
|
146
158
|
const skipCertVerify = this.isWssWithIp(this.config.wsUrl1);
|
|
@@ -188,6 +200,18 @@ class XiaoYiWebSocketManager extends events_1.EventEmitter {
|
|
|
188
200
|
async connectToServer2() {
|
|
189
201
|
console.log(`[Server2] Connecting to ${this.config.wsUrl2}...`);
|
|
190
202
|
try {
|
|
203
|
+
// ✅ Close existing connection before creating new one to prevent ghost connections
|
|
204
|
+
if (this.ws2) {
|
|
205
|
+
console.log(`[Server2] Closing existing connection before reconnect`);
|
|
206
|
+
try {
|
|
207
|
+
this.ws2.removeAllListeners();
|
|
208
|
+
this.ws2.close();
|
|
209
|
+
}
|
|
210
|
+
catch (err) {
|
|
211
|
+
console.warn(`[Server2] Error closing old connection:`, err);
|
|
212
|
+
}
|
|
213
|
+
this.ws2 = null;
|
|
214
|
+
}
|
|
191
215
|
const authHeaders = this.auth.generateAuthHeaders();
|
|
192
216
|
// Check if URL is wss + IP format, skip certificate verification
|
|
193
217
|
const skipCertVerify = this.isWssWithIp(this.config.wsUrl2);
|
|
@@ -235,12 +259,31 @@ class XiaoYiWebSocketManager extends events_1.EventEmitter {
|
|
|
235
259
|
disconnect() {
|
|
236
260
|
console.log("[WS Manager] Disconnecting from all servers...");
|
|
237
261
|
this.clearTimers();
|
|
262
|
+
// ✅ Properly cleanup WebSocket connections to prevent ghost connections
|
|
238
263
|
if (this.ws1) {
|
|
239
|
-
|
|
264
|
+
try {
|
|
265
|
+
console.log("[Server1] Removing all listeners and closing connection");
|
|
266
|
+
this.ws1.removeAllListeners();
|
|
267
|
+
if (this.ws1.readyState === ws_1.default.OPEN || this.ws1.readyState === ws_1.default.CONNECTING) {
|
|
268
|
+
this.ws1.close();
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
catch (err) {
|
|
272
|
+
console.warn("[Server1] Error during disconnect:", err);
|
|
273
|
+
}
|
|
240
274
|
this.ws1 = null;
|
|
241
275
|
}
|
|
242
276
|
if (this.ws2) {
|
|
243
|
-
|
|
277
|
+
try {
|
|
278
|
+
console.log("[Server2] Removing all listeners and closing connection");
|
|
279
|
+
this.ws2.removeAllListeners();
|
|
280
|
+
if (this.ws2.readyState === ws_1.default.OPEN || this.ws2.readyState === ws_1.default.CONNECTING) {
|
|
281
|
+
this.ws2.close();
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
catch (err) {
|
|
285
|
+
console.warn("[Server2] Error during disconnect:", err);
|
|
286
|
+
}
|
|
244
287
|
this.ws2 = null;
|
|
245
288
|
}
|
|
246
289
|
this.state1.connected = false;
|
|
@@ -257,6 +300,7 @@ class XiaoYiWebSocketManager extends events_1.EventEmitter {
|
|
|
257
300
|
}
|
|
258
301
|
this.sessionCleanupStateMap.clear();
|
|
259
302
|
this.emit("disconnected");
|
|
303
|
+
console.log("[WS Manager] Disconnect complete");
|
|
260
304
|
}
|
|
261
305
|
/**
|
|
262
306
|
* Send init message to specific server
|
package/package.json
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ynhcj/xiaoyi",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3-beta",
|
|
4
4
|
"description": "XiaoYi channel plugin for OpenClaw",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"xiaoyi.js",
|
|
17
|
+
"openclaw.plugin.json",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
7
20
|
"scripts": {
|
|
8
|
-
"build": "tsc
|
|
9
|
-
"prepublishOnly": "npm run build"
|
|
21
|
+
"build": "tsc"
|
|
10
22
|
},
|
|
11
23
|
"keywords": [
|
|
12
24
|
"openclaw",
|
|
@@ -43,7 +55,7 @@
|
|
|
43
55
|
}
|
|
44
56
|
},
|
|
45
57
|
"peerDependencies": {
|
|
46
|
-
"openclaw": "
|
|
58
|
+
"openclaw": ">=2026.3.1"
|
|
47
59
|
},
|
|
48
60
|
"peerDependenciesMeta": {
|
|
49
61
|
"openclaw": {
|
|
@@ -61,13 +73,6 @@
|
|
|
61
73
|
"@types/node-fetch": "^2.6.13",
|
|
62
74
|
"@types/uuid": "^10.0.0",
|
|
63
75
|
"@types/ws": "^8.5.10",
|
|
64
|
-
"openclaw": "^2026.3.13",
|
|
65
76
|
"typescript": "^5.3.3"
|
|
66
|
-
}
|
|
67
|
-
"files": [
|
|
68
|
-
"dist",
|
|
69
|
-
"xiaoyi.js",
|
|
70
|
-
"openclaw.plugin.json",
|
|
71
|
-
"README.md"
|
|
72
|
-
]
|
|
77
|
+
}
|
|
73
78
|
}
|