@kevisual/router 0.0.44 → 0.0.45

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/router.js CHANGED
@@ -6664,7 +6664,7 @@ class BunServer extends ServerBase {
6664
6664
  },
6665
6665
  websocket: {
6666
6666
  open: (ws) => {
6667
- ws.send({ type: 'connected' });
6667
+ ws.send(JSON.stringify({ type: 'connected' }));
6668
6668
  },
6669
6669
  message: async (ws, message) => {
6670
6670
  const pathname = ws.data.pathname || '';
@@ -6676,9 +6676,10 @@ class BunServer extends ServerBase {
6676
6676
  // WebSocket 连接关闭
6677
6677
  const id = ws?.data?.id || '';
6678
6678
  if (id) {
6679
- this.emitter.emit(id, { type: 'close', ws, id });
6679
+ this.emitter.emit('close--' + id, { type: 'close', ws, id });
6680
6680
  setTimeout(() => {
6681
6681
  // 关闭后 5 秒清理监听器, 避免内存泄漏, 理论上原本的自己就应该被清理掉了,这里是保险起见
6682
+ this.emitter.removeAllListeners('close--' + id);
6682
6683
  this.emitter.removeAllListeners(id);
6683
6684
  }, 5000);
6684
6685
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@kevisual/router",
4
- "version": "0.0.44",
4
+ "version": "0.0.45",
5
5
  "description": "",
6
6
  "type": "module",
7
7
  "main": "./dist/router.js",
@@ -223,7 +223,7 @@ export class BunServer extends ServerBase implements ServerType {
223
223
  },
224
224
  websocket: {
225
225
  open: (ws: any) => {
226
- ws.send({ type: 'connected' });
226
+ ws.send(JSON.stringify({ type: 'connected' }));
227
227
  },
228
228
  message: async (ws: any, message: string | Buffer) => {
229
229
  const pathname = ws.data.pathname || '';
@@ -235,9 +235,10 @@ export class BunServer extends ServerBase implements ServerType {
235
235
  // WebSocket 连接关闭
236
236
  const id = ws?.data?.id || '';
237
237
  if (id) {
238
- this.emitter.emit(id, { type: 'close', ws, id });
238
+ this.emitter.emit('close--' + id, { type: 'close', ws, id });
239
239
  setTimeout(() => {
240
240
  // 关闭后 5 秒清理监听器, 避免内存泄漏, 理论上原本的自己就应该被清理掉了,这里是保险起见
241
+ this.emitter.removeAllListeners('close--' + id);
241
242
  this.emitter.removeAllListeners(id);
242
243
  }, 5000);
243
244
  }