@maiyunnet/kebab 3.2.2 → 3.2.4

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/index.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * --- 本文件用来定义每个目录实体地址的常量 ---
6
6
  */
7
7
  /** --- 当前系统版本号 --- */
8
- export declare const VER = "3.2.2";
8
+ export declare const VER = "3.2.4";
9
9
  /** --- 框架根目录,以 / 结尾 --- */
10
10
  export declare const ROOT_PATH: string;
11
11
  export declare const LIB_PATH: string;
package/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * --- 本文件用来定义每个目录实体地址的常量 ---
7
7
  */
8
8
  /** --- 当前系统版本号 --- */
9
- export const VER = '3.2.2';
9
+ export const VER = '3.2.4';
10
10
  // --- 服务端用的路径 ---
11
11
  const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
12
12
  /** --- /xxx/xxx --- */
package/lib/ws.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Project: Kebab, User: JianSuoQiYue
3
3
  * Date: 2019-6-2 20:42
4
- * Last: 2020-4-9 22:33:11, 2022-09-13 13:32:01, 2022-12-30 19:13:07, 2024-2-6 23:53:45, 2024-12-23 01:33:16, 2025-1-28 21:05:51, 2025-9-23 12:27:48
4
+ * Last: 2020-4-9 22:33:11, 2022-09-13 13:32:01, 2022-12-30 19:13:07, 2024-2-6 23:53:45, 2024-12-23 01:33:16, 2025-1-28 21:05:51, 2025-9-23 12:27:48, 2025-10-4 23:20:32
5
5
  */
6
6
  import * as http from 'http';
7
7
  import * as net from 'net';
@@ -104,8 +104,7 @@ export declare class Socket {
104
104
  /** --- 绑定监听 --- */
105
105
  on(event: 'message', cb: (msg: {
106
106
  'opcode': EOpcode;
107
- 'buffer': Buffer;
108
- 'data': Buffer | string;
107
+ 'data': Buffer;
109
108
  }) => void | Promise<void>): this;
110
109
  on(event: 'error', cb: (error: any) => void | Promise<void>): this;
111
110
  on(event: 'drain' | 'close' | 'end', cb: () => void | Promise<void>): this;
package/lib/ws.js CHANGED
@@ -20,7 +20,9 @@ export var EOpcode;
20
20
  EOpcode[EOpcode["PING"] = 9] = "PING";
21
21
  EOpcode[EOpcode["PONG"] = 10] = "PONG";
22
22
  })(EOpcode || (EOpcode = {}));
23
- const liwsServer = liws.createServer();
23
+ const liwsServer = liws.createServer({
24
+ 'frameReceiveMode': EFrameReceiveMode.SIMPLE,
25
+ });
24
26
  export class Socket {
25
27
  constructor(request, socket, options = {}) {
26
28
  /** --- 还未开启监听时来的数据将存在这里 --- */
@@ -137,17 +139,17 @@ export class Socket {
137
139
  /** --- 创建成功后第一时间绑定事件 --- */
138
140
  _bindEvent() {
139
141
  this._ws.on('message', msg => {
140
- (async () => {
141
- if (msg.opcode === EOpcode.CLOSE) {
142
- return;
143
- }
144
- const buf = 'data' in msg ? Buffer.concat(msg.data) : await msg.toBuffer();
145
- this._on.message({
146
- 'opcode': msg.opcode,
147
- 'buffer': buf,
148
- 'data': msg.opcode === EOpcode.TEXT ? buf.toString() : buf,
149
- });
150
- })().catch(() => { });
142
+ if (msg.opcode === EOpcode.CLOSE) {
143
+ return;
144
+ }
145
+ if (!('data' in msg)) {
146
+ return;
147
+ }
148
+ const buf = Buffer.concat(msg.data);
149
+ this._on.message({
150
+ 'opcode': msg.opcode,
151
+ 'data': buf,
152
+ });
151
153
  }).on('drain', () => {
152
154
  this._on.drain();
153
155
  }).on('error', (e) => {
@@ -277,17 +279,16 @@ export function createServer(request, socket, options = {}) {
277
279
  * @param s2 第二个 socket
278
280
  */
279
281
  function bindPipe(s1, s2) {
280
- return new Promise((resolve) => {
282
+ return new Promise(resolve => {
281
283
  // --- 监听发送端的 ---
282
284
  s1.on('message', (msg) => {
283
285
  switch (msg.opcode) {
284
- case EOpcode.TEXT:
286
+ case EOpcode.TEXT: {
287
+ s2.writeText(msg.data.toString());
288
+ break;
289
+ }
285
290
  case EOpcode.BINARY: {
286
- if (typeof msg.data === 'string') {
287
- s2.writeText(msg.data);
288
- break;
289
- }
290
- s2.writeBinary(msg.buffer);
291
+ s2.writeBinary(msg.data);
291
292
  break;
292
293
  }
293
294
  case EOpcode.CLOSE: {
@@ -314,13 +315,12 @@ function bindPipe(s1, s2) {
314
315
  // --- 监听远程端的 ---
315
316
  s2.on('message', (msg) => {
316
317
  switch (msg.opcode) {
317
- case EOpcode.TEXT:
318
+ case EOpcode.TEXT: {
319
+ s1.writeText(msg.data.toString());
320
+ break;
321
+ }
318
322
  case EOpcode.BINARY: {
319
- if (typeof msg.data === 'string') {
320
- s1.writeText(msg.data);
321
- break;
322
- }
323
- s1.writeBinary(msg.buffer);
323
+ s1.writeBinary(msg.data);
324
324
  break;
325
325
  }
326
326
  case EOpcode.CLOSE: {
@@ -423,7 +423,7 @@ export async function rsocket(ctr, host, port) {
423
423
  switch (msg.opcode) {
424
424
  case EOpcode.TEXT:
425
425
  case EOpcode.BINARY: {
426
- socket.write(msg.buffer);
426
+ socket.write(msg.data);
427
427
  break;
428
428
  }
429
429
  case EOpcode.CLOSE: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maiyunnet/kebab",
3
- "version": "3.2.2",
3
+ "version": "3.2.4",
4
4
  "description": "Simple, easy-to-use, and fully-featured Node.js framework that is ready-to-use out of the box.",
5
5
  "type": "module",
6
6
  "keywords": [
package/sys/cmd.js CHANGED
@@ -195,7 +195,7 @@ async function run() {
195
195
  return;
196
196
  }
197
197
  // --- 载入独立文件入口 ---
198
- import('../ind/' + cmds[1] + '/index.js').catch((e) => {
198
+ import((!kebab.IND_CWD.startsWith('/') ? '/' : '') + kebab.IND_CWD + cmds[1] + '/index.js').catch((e) => {
199
199
  lCore.display('CMD ERROR', 'E', e);
200
200
  });
201
201
  }
package/sys/route.js CHANGED
@@ -274,7 +274,7 @@ export async function run(data) {
274
274
  wsSocket.on('message', async function (msg) {
275
275
  switch (msg.opcode) {
276
276
  case ws.EOpcode.CLOSE: {
277
- const r = await cctr['onMessage'](msg.buffer, msg.opcode);
277
+ const r = await cctr['onMessage'](msg.data, msg.opcode);
278
278
  if (r === false) {
279
279
  break;
280
280
  }
@@ -282,7 +282,7 @@ export async function run(data) {
282
282
  break;
283
283
  }
284
284
  case ws.EOpcode.PING: {
285
- const r = await cctr['onMessage'](msg.buffer, msg.opcode);
285
+ const r = await cctr['onMessage'](msg.data, msg.opcode);
286
286
  if (r === false) {
287
287
  break;
288
288
  }
@@ -292,11 +292,11 @@ export async function run(data) {
292
292
  case ws.EOpcode.BINARY:
293
293
  case ws.EOpcode.TEXT: {
294
294
  try {
295
- const r = await cctr['onMessage'](msg.buffer, msg.opcode);
295
+ const r = await cctr['onMessage'](msg.data, msg.opcode);
296
296
  if (r === false) {
297
297
  break;
298
298
  }
299
- const wrtn = await cctr['onData'](msg.data, msg.opcode);
299
+ const wrtn = await cctr['onData'](msg.opcode === ws.EOpcode.TEXT ? msg.data.toString() : msg.data, msg.opcode);
300
300
  if (wrtn === false) {
301
301
  wsSocket.end();
302
302
  return;