@lzpong/httpm 1.0.1 → 1.0.3

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 (3) hide show
  1. package/README.md +10 -1
  2. package/httpm.js +5 -5
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -229,12 +229,21 @@ wss.getConnections(); // 获取所有连接
229
229
 
230
230
  | 事件 | 说明 |
231
231
  |------|------|
232
- | `message` | 接收消息(文本或二进制) |
232
+ | `data` | 接收消息(`{ type: 'text'/'binary', data }`) |
233
233
  | `text` | 接收文本消息 |
234
234
  | `binary` | 接收二进制消息 |
235
235
  | `close` | 连接关闭 |
236
236
  | `error` | 连接错误 |
237
237
 
238
+ ### data 事件使用
239
+
240
+ ```javascript
241
+ ws.on('data', (msg) => {
242
+ console.log(msg.type); // 'text' 或 'binary'
243
+ console.log(msg.data); // 消息内容
244
+ });
245
+ ```
246
+
238
247
  ## SSE (Server-Sent Events)
239
248
 
240
249
  ### 简化注册
package/httpm.js CHANGED
@@ -915,12 +915,12 @@ class WebSocket {
915
915
  switch (opcode) {
916
916
  case 0x01: { // 文本帧
917
917
  const text = payload.toString('utf8');
918
- this._emit('message', text);
918
+ this._emit('data', { type: 'text', data: text });
919
919
  this._emit('text', text);
920
920
  break;
921
921
  }
922
922
  case 0x02: { // 二进制帧
923
- this._emit('message', payload);
923
+ this._emit('data', { type: 'binary', data: payload });
924
924
  this._emit('binary', payload);
925
925
  break;
926
926
  }
@@ -2026,9 +2026,9 @@ class Application extends Router {
2026
2026
  const sseInstance = res.sse();
2027
2027
  const cleanup = handler(sseInstance, req);
2028
2028
  // 连接关闭时执行清理
2029
- res._res.on('close', () => {
2030
- if (typeof cleanup === 'function') cleanup();
2031
- });
2029
+ if (typeof cleanup === 'function') {
2030
+ res._res.on('close', cleanup);
2031
+ }
2032
2032
  });
2033
2033
  }
2034
2034
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lzpong/httpm",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "基于 Node.js 原生模块的单文件、零依赖 HTTP 服务库,兼容 Express API",
5
5
  "main": "httpm.js",
6
6
  "files": [