@ives_xxz/framework 1.0.4 → 1.0.6
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/define/FWEventDefine.ts +1 -0
- package/log/FWLog.ts +73 -56
- package/manager/FWTaskManager.ts +1 -1
- package/manager/FWTimeManager.ts +1 -1
- package/package.json +1 -1
- package/service/socket/FWSocket.ts +19 -11
- package/service/socket/FWSocketSender.ts +3 -3
- package/utils/FWTask.ts +32 -18
package/define/FWEventDefine.ts
CHANGED
package/log/FWLog.ts
CHANGED
|
@@ -26,83 +26,100 @@ class FWLog {
|
|
|
26
26
|
private constructor() {}
|
|
27
27
|
|
|
28
28
|
public get debug() {
|
|
29
|
-
|
|
30
|
-
window.console
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
if (cc.sys.isBrowser)
|
|
30
|
+
return window.console.log.bind(
|
|
31
|
+
window.console,
|
|
32
|
+
`%c[debug]:${FW.Entry.timeMgr.getTime()}`,
|
|
33
|
+
`color: black; background-color: ${FWLogColorMap.get(
|
|
34
|
+
FWSystemDefine.FWLogType.DEBUG,
|
|
35
|
+
)}; font-weight: bold; font-size: 10;`,
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
return console.log;
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
get send() {
|
|
39
|
-
|
|
40
|
-
window.console
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
if (cc.sys.isBrowser)
|
|
43
|
+
return window.console.log.bind(
|
|
44
|
+
window.console,
|
|
45
|
+
`%c[sendMsg]:${FW.Entry.timeMgr.getTime()}`,
|
|
46
|
+
`color: black; background-color: ${FWLogColorMap.get(
|
|
47
|
+
FWSystemDefine.FWLogType.SOCKET_SEND,
|
|
48
|
+
)}; font-weight: bold; font-size: 10;`,
|
|
49
|
+
);
|
|
50
|
+
return console.log;
|
|
46
51
|
}
|
|
47
52
|
|
|
48
53
|
get receive() {
|
|
49
|
-
|
|
50
|
-
window.console
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
if (cc.sys.isBrowser)
|
|
55
|
+
return window.console.log.bind(
|
|
56
|
+
window.console,
|
|
57
|
+
`%c[receiveMsg]:${FW.Entry.timeMgr.getTime()}`,
|
|
58
|
+
`color: black; background-color: ${FWLogColorMap.get(
|
|
59
|
+
FWSystemDefine.FWLogType.SOCKET_RECEIVE,
|
|
60
|
+
)}; font-weight: bold; font-size: 10;`,
|
|
61
|
+
);
|
|
62
|
+
return console.log;
|
|
56
63
|
}
|
|
57
64
|
|
|
58
65
|
get request() {
|
|
59
|
-
|
|
60
|
-
window.console
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
+
if (cc.sys.isBrowser)
|
|
67
|
+
return window.console.log.bind(
|
|
68
|
+
window.console,
|
|
69
|
+
`%c[request]:${FW.Entry.timeMgr.getTime()}`,
|
|
70
|
+
`color: black; background-color: ${FWLogColorMap.get(
|
|
71
|
+
FWSystemDefine.FWLogType.REQUEST,
|
|
72
|
+
)}; font-weight: bold; font-size: 10;`,
|
|
73
|
+
);
|
|
74
|
+
return console.log;
|
|
66
75
|
}
|
|
67
76
|
|
|
68
77
|
get response() {
|
|
69
|
-
|
|
70
|
-
window.console
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
78
|
+
if (cc.sys.isBrowser)
|
|
79
|
+
return window.console.log.bind(
|
|
80
|
+
window.console,
|
|
81
|
+
`%c[response]:${FW.Entry.timeMgr.getTime()}`,
|
|
82
|
+
`color: black; background-color: ${FWLogColorMap.get(
|
|
83
|
+
FWSystemDefine.FWLogType.RESPONSE,
|
|
84
|
+
)}; font-weight: bold; font-size: 10;`,
|
|
85
|
+
);
|
|
86
|
+
return console.log;
|
|
76
87
|
}
|
|
77
88
|
|
|
78
89
|
get system() {
|
|
79
|
-
|
|
80
|
-
window.console
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
90
|
+
if (cc.sys.isBrowser)
|
|
91
|
+
return window.console.log.bind(
|
|
92
|
+
window.console,
|
|
93
|
+
`%c[system]:${FW.Entry.timeMgr.getTime()}`,
|
|
94
|
+
`color: black; background-color: ${FWLogColorMap.get(
|
|
95
|
+
FWSystemDefine.FWLogType.SYSTEM,
|
|
96
|
+
)}; font-weight: bold; font-size: 10;`,
|
|
97
|
+
);
|
|
98
|
+
return console.log;
|
|
86
99
|
}
|
|
87
100
|
|
|
88
101
|
get warn() {
|
|
89
|
-
|
|
90
|
-
window.console
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
102
|
+
if (cc.sys.isBrowser)
|
|
103
|
+
return window.console.warn.bind(
|
|
104
|
+
window.console,
|
|
105
|
+
`%c[warn]:${FW.Entry.timeMgr.getTime()}`,
|
|
106
|
+
`color: black; background-color: ${FWLogColorMap.get(
|
|
107
|
+
FWSystemDefine.FWLogType.WARN,
|
|
108
|
+
)}; font-weight: bold; font-size: 10;`,
|
|
109
|
+
);
|
|
110
|
+
return console.warn;
|
|
96
111
|
}
|
|
97
112
|
|
|
98
113
|
get error() {
|
|
99
|
-
|
|
100
|
-
window.console
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
114
|
+
if (cc.sys.isBrowser)
|
|
115
|
+
return window.console.error.bind(
|
|
116
|
+
window.console,
|
|
117
|
+
`%c[error]:${FW.Entry.timeMgr.getTime()}`,
|
|
118
|
+
`color: black; background-color: ${FWLogColorMap.get(
|
|
119
|
+
FWSystemDefine.FWLogType.ERROR,
|
|
120
|
+
)}; font-weight: bold; font-size: 10;`,
|
|
121
|
+
);
|
|
122
|
+
return console.error;
|
|
106
123
|
}
|
|
107
124
|
}
|
|
108
125
|
|
package/manager/FWTaskManager.ts
CHANGED
package/manager/FWTimeManager.ts
CHANGED
|
@@ -69,7 +69,7 @@ export class FWTimeManager extends FWManager implements FW.TimeManager {
|
|
|
69
69
|
cb: () => void,
|
|
70
70
|
time?: number,
|
|
71
71
|
repeat?: number,
|
|
72
|
-
target?:
|
|
72
|
+
target?: FW.TargetType,
|
|
73
73
|
tag?: string,
|
|
74
74
|
): FW.TimerSchedule {
|
|
75
75
|
const timer = new FWTimer();
|
package/package.json
CHANGED
|
@@ -157,9 +157,7 @@ export default class FWSocket implements FW.Socket {
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
reconnect(force?: boolean) {
|
|
160
|
-
if (force)
|
|
161
|
-
this.reconnectTimes = 0;
|
|
162
|
-
}
|
|
160
|
+
if (force) this.reconnectTimes = 0;
|
|
163
161
|
|
|
164
162
|
FWLog.debug(
|
|
165
163
|
`socket reconnect : reconnectTimes->${this.reconnectTimes},maxReconnectTimes->${this.maxReconnectTimes}`,
|
|
@@ -241,7 +239,11 @@ export default class FWSocket implements FW.Socket {
|
|
|
241
239
|
}
|
|
242
240
|
|
|
243
241
|
private sendMessage(msg: any) {
|
|
244
|
-
|
|
242
|
+
try {
|
|
243
|
+
this.socket?.send(this.sender.onBeforeSendingMessage?.(msg) || msg);
|
|
244
|
+
} catch (e) {
|
|
245
|
+
this.socket?.send(msg);
|
|
246
|
+
}
|
|
245
247
|
}
|
|
246
248
|
|
|
247
249
|
/** socket关闭 */
|
|
@@ -266,6 +268,19 @@ export default class FWSocket implements FW.Socket {
|
|
|
266
268
|
return;
|
|
267
269
|
}
|
|
268
270
|
|
|
271
|
+
this.remoteProtocol(msg);
|
|
272
|
+
|
|
273
|
+
if (this.isPausedMessageHandle) return;
|
|
274
|
+
|
|
275
|
+
this.handle?.onMessage?.(msg);
|
|
276
|
+
}
|
|
277
|
+
/** 错误处理 */
|
|
278
|
+
private async onSocketError(msg: any) {
|
|
279
|
+
await this.remoteProtocol(msg);
|
|
280
|
+
this.handle?.onError?.(msg);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
private async remoteProtocol(msg: any) {
|
|
269
284
|
const protocolKey = await this.handle.getProtocolKey?.(msg);
|
|
270
285
|
if (protocolKey && this.protocolRegistry.has(protocolKey)) {
|
|
271
286
|
const symbolSet = this.protocolRegistry.get(protocolKey);
|
|
@@ -282,12 +297,5 @@ export default class FWSocket implements FW.Socket {
|
|
|
282
297
|
}
|
|
283
298
|
}
|
|
284
299
|
}
|
|
285
|
-
|
|
286
|
-
if (this.isPausedMessageHandle) return;
|
|
287
|
-
this.handle?.onMessage?.(msg);
|
|
288
|
-
}
|
|
289
|
-
/** 错误处理 */
|
|
290
|
-
private onSocketError(msg: any) {
|
|
291
|
-
this.handle?.onError?.(msg);
|
|
292
300
|
}
|
|
293
301
|
}
|
|
@@ -9,11 +9,11 @@ export default class FWSocketSender implements FW.SocketSender {
|
|
|
9
9
|
initialize?();
|
|
10
10
|
onDestroy?();
|
|
11
11
|
sendHeart?();
|
|
12
|
+
onHeart?(msg: any): Promise<boolean>;
|
|
13
|
+
onBeforeSendingMessage?(msg: any): string;
|
|
14
|
+
getProtocolKey?(msg: any): string;
|
|
12
15
|
|
|
13
16
|
send(msg: any) {
|
|
14
17
|
FW.Entry.socketMgr.getSocket()?.send(msg);
|
|
15
18
|
}
|
|
16
|
-
onHeart?(msg: any): Promise<boolean>;
|
|
17
|
-
onBeforeSendingMessage?(msg: any): string;
|
|
18
|
-
getProtocolKey?(msg: any): string;
|
|
19
19
|
}
|
package/utils/FWTask.ts
CHANGED
|
@@ -47,6 +47,7 @@ export default class FWTask implements FW.Task {
|
|
|
47
47
|
taskId,
|
|
48
48
|
});
|
|
49
49
|
this.taskStartTime = FW.Entry.timeMgr.getTime();
|
|
50
|
+
FWLog.debug('执行任务开始', this.taskStartTime);
|
|
50
51
|
await this.executeFrame();
|
|
51
52
|
return this;
|
|
52
53
|
}
|
|
@@ -118,32 +119,45 @@ export default class FWTask implements FW.Task {
|
|
|
118
119
|
performance.now() - frameStart < this.frameBudget
|
|
119
120
|
) {
|
|
120
121
|
const task = this.taskQueue[0];
|
|
121
|
-
|
|
122
122
|
const taskId = (task as any).taskId || `id-${processed}`;
|
|
123
123
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
try {
|
|
125
|
+
const result = await task.next();
|
|
126
|
+
|
|
127
|
+
if (result.done) {
|
|
128
|
+
this.taskQueue.shift();
|
|
129
|
+
this.recordEvent({
|
|
130
|
+
type: FWEventDefine.TaskEvent.COMPLETE,
|
|
131
|
+
progress: 1,
|
|
132
|
+
message: '任务完成',
|
|
133
|
+
taskId,
|
|
134
|
+
});
|
|
135
|
+
} else if (result.value) {
|
|
136
|
+
this.recordEvent({
|
|
137
|
+
...result.value,
|
|
138
|
+
taskId,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
frameTasks.push({
|
|
143
|
+
taskId: taskId,
|
|
144
|
+
result: result.done ? FWEventDefine.TaskEvent.COMPLETE : FWEventDefine.TaskEvent.YIELDED,
|
|
145
|
+
message: (result?.value as any)?.message,
|
|
146
|
+
});
|
|
147
|
+
} catch (error) {
|
|
148
|
+
FWLog.error('执行任务出错', error);
|
|
127
149
|
this.taskQueue.shift();
|
|
128
150
|
this.recordEvent({
|
|
129
|
-
type: FWEventDefine.TaskEvent.
|
|
130
|
-
|
|
131
|
-
message: '任务完成',
|
|
151
|
+
type: FWEventDefine.TaskEvent.ERROR,
|
|
152
|
+
message: `任务执行出错: ${error.message}`,
|
|
132
153
|
taskId,
|
|
133
154
|
});
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
155
|
+
frameTasks.push({
|
|
156
|
+
taskId: taskId,
|
|
157
|
+
result: FWEventDefine.TaskEvent.ERROR,
|
|
158
|
+
message: error.message,
|
|
138
159
|
});
|
|
139
160
|
}
|
|
140
|
-
|
|
141
|
-
frameTasks.push({
|
|
142
|
-
taskId: taskId,
|
|
143
|
-
result: result.done ? FWEventDefine.TaskEvent.COMPLETE : FWEventDefine.TaskEvent.YIELDED,
|
|
144
|
-
message: (result?.value as any)?.message,
|
|
145
|
-
});
|
|
146
|
-
|
|
147
161
|
processed++;
|
|
148
162
|
}
|
|
149
163
|
|