ework-qq-bridge 0.2.0 → 0.2.1
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/onebot.ts +5 -1
- package/tests/bridge.test.ts +17 -0
package/package.json
CHANGED
package/src/onebot.ts
CHANGED
|
@@ -123,7 +123,11 @@ export function createOneBotServer(opts: OneBotServerOptions) {
|
|
|
123
123
|
void opts.onEvent(ev);
|
|
124
124
|
}
|
|
125
125
|
},
|
|
126
|
-
close() {
|
|
126
|
+
close(client: ServerWebSocket<unknown>) {
|
|
127
|
+
// A reconnect race can fire the OLD socket's close after the NEW
|
|
128
|
+
// socket's open; only tear down when the active client is the one
|
|
129
|
+
// that closed, else the live connection is orphaned.
|
|
130
|
+
if (ws !== client) return;
|
|
127
131
|
rejectAll("connection closed");
|
|
128
132
|
},
|
|
129
133
|
},
|
package/tests/bridge.test.ts
CHANGED
|
@@ -144,3 +144,20 @@ describe("chat mode", () => {
|
|
|
144
144
|
expect(replies[0]).toContain("没看懂指令");
|
|
145
145
|
});
|
|
146
146
|
});
|
|
147
|
+
|
|
148
|
+
test("onebot close ignores non-active client (reconnect race)", () => {
|
|
149
|
+
const { createOneBotServer } = require("../src/onebot");
|
|
150
|
+
let ready = 0;
|
|
151
|
+
const srv = createOneBotServer({ path: "/ws", accessToken: "t", onEvent: () => {}, onReady: () => { ready++; } });
|
|
152
|
+
const fake = (id: string) => ({ id, send: () => {}, close: () => {} });
|
|
153
|
+
const a = fake("a"), b = fake("b");
|
|
154
|
+
srv.handlers.open(a);
|
|
155
|
+
expect(ready).toBe(1);
|
|
156
|
+
srv.handlers.open(b);
|
|
157
|
+
expect(ready).toBe(1);
|
|
158
|
+
srv.handlers.close(a);
|
|
159
|
+
expect(srv.connected).toBe(true);
|
|
160
|
+
srv.handlers.close(b);
|
|
161
|
+
expect(srv.connected).toBe(false);
|
|
162
|
+
});
|
|
163
|
+
|