@ives_xxz/framework 1.0.5 → 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.
@@ -22,5 +22,6 @@ export namespace FWEventDefine {
22
22
  FRAME_END = 'FRAME_END',
23
23
  QUEUE = 'QUEUE',
24
24
  ALL_COMPLETE = 'ALL_COMPLETE',
25
+ ERROR = 'ERROR',
25
26
  }
26
27
  }
package/log/FWLog.ts CHANGED
@@ -26,83 +26,100 @@ class FWLog {
26
26
  private constructor() {}
27
27
 
28
28
  public get debug() {
29
- return window.console.log.bind(
30
- window.console,
31
- `%c[debug]:${FW.Entry.timeMgr.getTime()}`,
32
- `color: black; background-color: ${FWLogColorMap.get(
33
- FWSystemDefine.FWLogType.DEBUG,
34
- )}; font-weight: bold; font-size: 10;`,
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
- return window.console.log.bind(
40
- window.console,
41
- `%c[sendMsg]:${FW.Entry.timeMgr.getTime()}`,
42
- `color: black; background-color: ${FWLogColorMap.get(
43
- FWSystemDefine.FWLogType.SOCKET_SEND,
44
- )}; font-weight: bold; font-size: 10;`,
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
- return window.console.log.bind(
50
- window.console,
51
- `%c[receiveMsg]:${FW.Entry.timeMgr.getTime()}`,
52
- `color: black; background-color: ${FWLogColorMap.get(
53
- FWSystemDefine.FWLogType.SOCKET_RECEIVE,
54
- )}; font-weight: bold; font-size: 10;`,
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
- return window.console.log.bind(
60
- window.console,
61
- `%c[request]:${FW.Entry.timeMgr.getTime()}`,
62
- `color: black; background-color: ${FWLogColorMap.get(
63
- FWSystemDefine.FWLogType.REQUEST,
64
- )}; font-weight: bold; font-size: 10;`,
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
- return window.console.log.bind(
70
- window.console,
71
- `%c[response]:${FW.Entry.timeMgr.getTime()}`,
72
- `color: black; background-color: ${FWLogColorMap.get(
73
- FWSystemDefine.FWLogType.RESPONSE,
74
- )}; font-weight: bold; font-size: 10;`,
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
- return window.console.log.bind(
80
- window.console,
81
- `%c[system]:${FW.Entry.timeMgr.getTime()}`,
82
- `color: black; background-color: ${FWLogColorMap.get(
83
- FWSystemDefine.FWLogType.SYSTEM,
84
- )}; font-weight: bold; font-size: 10;`,
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
- return window.console.warn.bind(
90
- window.console,
91
- `%c[warn]:${FW.Entry.timeMgr.getTime()}`,
92
- `color: black; background-color: ${FWLogColorMap.get(
93
- FWSystemDefine.FWLogType.WARN,
94
- )}; font-weight: bold; font-size: 10;`,
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
- return window.console.error.bind(
100
- window.console,
101
- `%c[error]:${FW.Entry.timeMgr.getTime()}`,
102
- `color: black; background-color: ${FWLogColorMap.get(
103
- FWSystemDefine.FWLogType.ERROR,
104
- )}; font-weight: bold; font-size: 10;`,
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
 
@@ -7,7 +7,7 @@ export default class FWTaskManager extends FWManager implements FW.TaskManager {
7
7
  /**
8
8
  * 任务合集
9
9
  */
10
- private tasks: Map<number, FWTask> = new Map();
10
+ private tasks: Map<number, FWTask> = new Map<number, FWTask>();
11
11
  /**
12
12
  * 任务id
13
13
  */
@@ -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?: Comment | Object | cc.Node,
72
+ target?: FW.TargetType,
73
73
  tag?: string,
74
74
  ): FW.TimerSchedule {
75
75
  const timer = new FWTimer();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ives_xxz/framework",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "cocoscreator 2.x mvc framework",
5
5
  "main": "index.js",
6
6
  "keywords": [
@@ -1,7 +1,7 @@
1
- import { FWSystemConfig } from "../../config/FWSystemConfig";
2
- import FWLog from "../../log/FWLog";
3
- import FWSocketHandle from "./FWSocketHandle";
4
- import FWSocketSender from "./FWSocketSender";
1
+ import { FWSystemConfig } from '../../config/FWSystemConfig';
2
+ import FWLog from '../../log/FWLog';
3
+ import FWSocketHandle from './FWSocketHandle';
4
+ import FWSocketSender from './FWSocketSender';
5
5
 
6
6
  /**
7
7
  * TODO 犹豫socket没有改版暂时已老的cmd字符串映射方式做,后期优化
@@ -67,7 +67,7 @@ export default class FWSocket implements FW.Socket {
67
67
  tag: string,
68
68
  sender: FW.SocketSender,
69
69
  handle: FW.SocketHandle,
70
- config: FW.SocketConfig
70
+ config: FW.SocketConfig,
71
71
  ): FW.SocketPromiseProxy {
72
72
  FW.Entry.timeMgr.unSchedule(this);
73
73
 
@@ -94,12 +94,9 @@ export default class FWSocket implements FW.Socket {
94
94
  this.heartInternal = config?.heartInternal || defaultConfig.heartInternal;
95
95
  this.heartTimeout = config?.heartTimeout || defaultConfig.heartTimeout;
96
96
  this.heartWeakTime = config?.heartWeakTime || defaultConfig.heartWeakTime;
97
- this.maxReconnectTimes =
98
- config?.maxReconnectTimes || defaultConfig.maxReconnectTimes;
99
- this.reconnectInternal =
100
- config?.reconnectInternal || defaultConfig.reconnectInternal;
101
- this.protocolSymbol =
102
- config?.protocolSymbol || defaultConfig.protocolSymbol;
97
+ this.maxReconnectTimes = config?.maxReconnectTimes || defaultConfig.maxReconnectTimes;
98
+ this.reconnectInternal = config?.reconnectInternal || defaultConfig.reconnectInternal;
99
+ this.protocolSymbol = config?.protocolSymbol || defaultConfig.protocolSymbol;
103
100
 
104
101
  this.promiseProxy = {
105
102
  promise: undefined,
@@ -160,12 +157,10 @@ export default class FWSocket implements FW.Socket {
160
157
  }
161
158
 
162
159
  reconnect(force?: boolean) {
163
- if (force) {
164
- this.reconnectTimes = 0;
165
- }
160
+ if (force) this.reconnectTimes = 0;
166
161
 
167
162
  FWLog.debug(
168
- `socket reconnect : reconnectTimes->${this.reconnectTimes},maxReconnectTimes->${this.maxReconnectTimes}`
163
+ `socket reconnect : reconnectTimes->${this.reconnectTimes},maxReconnectTimes->${this.maxReconnectTimes}`,
169
164
  );
170
165
  if (++this.reconnectTimes >= this.maxReconnectTimes) {
171
166
  this.handle?.onTimeout?.();
@@ -192,8 +187,7 @@ export default class FWSocket implements FW.Socket {
192
187
  const protocolKey = this.sender.getProtocolKey?.(msg);
193
188
  if (protocolKey) {
194
189
  const symbol = Symbol(protocolKey);
195
- const registry =
196
- this.protocolRegistry.get(protocolKey) || new Set<Symbol>();
190
+ const registry = this.protocolRegistry.get(protocolKey) || new Set<Symbol>();
197
191
  this.protocolRegistry.set(protocolKey, registry.add(symbol));
198
192
  this.protocolContainer.set(symbol, msg);
199
193
  }
@@ -203,7 +197,7 @@ export default class FWSocket implements FW.Socket {
203
197
 
204
198
  /** 连接打开 */
205
199
  private onSocketOpen() {
206
- FWLog.debug("on open!");
200
+ FWLog.debug('on open!');
207
201
  FW.Entry.timeMgr.unSchedule(this);
208
202
  this.reconnectTimes = 0;
209
203
  this.sendHeartTimestamp = 0;
@@ -235,7 +229,7 @@ export default class FWSocket implements FW.Socket {
235
229
  },
236
230
  this.heartInternal / 1000,
237
231
  cc.macro.REPEAT_FOREVER,
238
- this
232
+ this,
239
233
  );
240
234
  }
241
235
 
@@ -258,11 +252,11 @@ export default class FWSocket implements FW.Socket {
258
252
  FW.Entry.timeMgr.scheduleOnce(
259
253
  () => {
260
254
  if (!this.isReconnect) return;
261
- FWLog.debug("on close!");
255
+ FWLog.debug('on close!');
262
256
  this.reconnect();
263
257
  },
264
258
  this.reconnectInternal,
265
- this
259
+ this,
266
260
  );
267
261
  }
268
262
  /** 消息处理 */
@@ -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
- const result = await task.next();
125
-
126
- if (result.done) {
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.COMPLETE,
130
- progress: 1,
131
- message: '任务完成',
151
+ type: FWEventDefine.TaskEvent.ERROR,
152
+ message: `任务执行出错: ${error.message}`,
132
153
  taskId,
133
154
  });
134
- } else if (result.value) {
135
- this.recordEvent({
136
- ...result.value,
137
- taskId,
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