@maiyunnet/kebab 3.2.6 → 3.2.7
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 +1 -1
- package/index.js +1 -1
- package/lib/ws.js +4 -1
- package/package.json +1 -1
- package/sys/ctr.d.ts +5 -2
- package/www/example/ctr/test.js +3 -0
- package/www/example/ws/test.js +4 -4
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
7
7
|
*/
|
|
8
8
|
/** --- 当前系统版本号 --- */
|
|
9
|
-
export const VER = '3.2.
|
|
9
|
+
export const VER = '3.2.7';
|
|
10
10
|
// --- 服务端用的路径 ---
|
|
11
11
|
const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
|
|
12
12
|
/** --- /xxx/xxx --- */
|
package/lib/ws.js
CHANGED
|
@@ -177,11 +177,14 @@ export class Socket {
|
|
|
177
177
|
break;
|
|
178
178
|
}
|
|
179
179
|
case 'end': {
|
|
180
|
+
if (!this._ws.ended) {
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
180
183
|
cb();
|
|
181
184
|
break;
|
|
182
185
|
}
|
|
183
186
|
default: {
|
|
184
|
-
// --- close ---
|
|
187
|
+
// --- drain, close ---
|
|
185
188
|
if (!this._close) {
|
|
186
189
|
break;
|
|
187
190
|
}
|
package/package.json
CHANGED
package/sys/ctr.d.ts
CHANGED
|
@@ -111,11 +111,14 @@ export declare class Ctr {
|
|
|
111
111
|
'timeout'?: number;
|
|
112
112
|
};
|
|
113
113
|
/**
|
|
114
|
-
* --- WebSocket 下当收到数据时会自动被调用的事件,即只文本和二进制数据,返回内容会被发送给 socket
|
|
114
|
+
* --- WebSocket 下当收到数据时会自动被调用的事件,即只文本和二进制数据,返回内容会被发送给 socket ---
|
|
115
|
+
* --- 但返回 false 连接会被中断,什么都不返回则什么都不做 ---
|
|
115
116
|
*/
|
|
116
117
|
onData(data: Buffer | string, opcode: lWs.EOpcode): kebab.Json;
|
|
117
118
|
/**
|
|
118
|
-
* --- 包含所有 opcode 的消息,若要发送数据需自行调用 write 方法,data 恒定为原始 buffer
|
|
119
|
+
* --- 包含所有 opcode 的消息,若要发送数据需自行调用 write 方法,data 恒定为原始 buffer ---
|
|
120
|
+
* --- 返回 false 则不会执行默认方法,一般请什么都不要返回 ---
|
|
121
|
+
* --- 返回 false 链接也不会中断 ---
|
|
119
122
|
* @param data 数据
|
|
120
123
|
* @param opcode opcode
|
|
121
124
|
*/
|
package/www/example/ctr/test.js
CHANGED
|
@@ -2790,6 +2790,9 @@ setInterval(() => {
|
|
|
2790
2790
|
ws.on('message', (frame) => {
|
|
2791
2791
|
echo.push('<div>Server: ' + frame.data.toString() + '.</div>');
|
|
2792
2792
|
});
|
|
2793
|
+
ws.on('end', () => {
|
|
2794
|
+
lCore.display('CLIENT onEnd');
|
|
2795
|
+
});
|
|
2793
2796
|
ws.on('close', () => {
|
|
2794
2797
|
resolve();
|
|
2795
2798
|
});
|
package/www/example/ws/test.js
CHANGED
|
@@ -7,13 +7,13 @@ export default class extends sCtr.Ctr {
|
|
|
7
7
|
this._nick = '';
|
|
8
8
|
}
|
|
9
9
|
onUpgrade() {
|
|
10
|
-
lCore.
|
|
10
|
+
lCore.display('[/test] WebSocket test onUpgrade.');
|
|
11
11
|
return {
|
|
12
12
|
'timeout': 60_000 * 2,
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
onLoad() {
|
|
16
|
-
lCore.
|
|
16
|
+
lCore.display('[/test] WebSocket test onLoad.');
|
|
17
17
|
setTimeout(() => {
|
|
18
18
|
if (!this._nick) {
|
|
19
19
|
return;
|
|
@@ -32,11 +32,11 @@ export default class extends sCtr.Ctr {
|
|
|
32
32
|
}
|
|
33
33
|
// --- 用户消息 ---
|
|
34
34
|
const date = new Date();
|
|
35
|
-
lCore.
|
|
35
|
+
lCore.display('[/test] [' + date.getHours().toString().padStart(2, '0') + ':' + date.getMinutes().toString().padStart(2, '0') + ':' + date.getSeconds().toString().padStart(2, '0') + '] WebSocket test onData, data: ' + data);
|
|
36
36
|
return '<b>' + this._nick + ':</b> ' + data;
|
|
37
37
|
}
|
|
38
38
|
onClose() {
|
|
39
|
-
lCore.
|
|
39
|
+
lCore.display('[/test] WebSocket test onClose, nick: ' + this._nick);
|
|
40
40
|
this._nick = '';
|
|
41
41
|
}
|
|
42
42
|
}
|