@ives_xxz/framework 1.2.18 → 1.2.19

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/FW.d.ts CHANGED
@@ -219,6 +219,11 @@ declare namespace FW {
219
219
  socket: FW.Socket;
220
220
  };
221
221
 
222
+ type ProtocolPolling = {
223
+ msg: string;
224
+ schedule: TimerSchedule;
225
+ };
226
+
222
227
  type Socket = {
223
228
  public onDestroy(): void;
224
229
  /**
@@ -275,6 +280,7 @@ declare namespace FW {
275
280
  maxReconnectTimes: number;
276
281
  reconnectInternal: number;
277
282
  protocolSymbol: Symbol;
283
+ protocolPollingTime: number;
278
284
  };
279
285
 
280
286
  /**
@@ -6,5 +6,6 @@ export namespace FWSystemConfig {
6
6
  maxReconnectTimes: 10,
7
7
  reconnectInternal: 3000,
8
8
  protocolSymbol: null,
9
+ protocolPollingTime: 10,
9
10
  };
10
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ives_xxz/framework",
3
- "version": "1.2.18",
3
+ "version": "1.2.19",
4
4
  "description": "cocoscreator 2.x mvc framework",
5
5
  "main": "index.js",
6
6
  "keywords": [
@@ -39,10 +39,12 @@ export default class FWSocket implements FW.Socket {
39
39
  private promiseProxy: FW.SocketPromiseProxy;
40
40
  /** 协议符号 */
41
41
  private protocolSymbol: FW.Symbol;
42
+ /** 协议轮询时间 */
43
+ private protocolPollingTime: number;
42
44
  /** 协议注册表 */
43
45
  private protocolRegistry: Map<string, Set<Symbol>>;
44
46
  /** 协议符号容器 */
45
- private protocolContainer: Map<Symbol, string>;
47
+ private protocolContainer: Map<Symbol, FW.ProtocolPolling>;
46
48
 
47
49
  /**
48
50
  * 消息事件列表
@@ -56,7 +58,7 @@ export default class FWSocket implements FW.Socket {
56
58
 
57
59
  public initialize(): void {
58
60
  this.messageEvents = cc.js.createMap();
59
- this.protocolContainer = new Map<Symbol, string>();
61
+ this.protocolContainer = new Map<Symbol, FW.ProtocolPolling>();
60
62
  this.protocolRegistry = new Map<string, Set<Symbol>>();
61
63
  this.reconnectTimes = 0;
62
64
  }
@@ -96,6 +98,7 @@ export default class FWSocket implements FW.Socket {
96
98
  this.maxReconnectTimes = config?.maxReconnectTimes || defaultConfig.maxReconnectTimes;
97
99
  this.reconnectInternal = config?.reconnectInternal || defaultConfig.reconnectInternal;
98
100
  this.protocolSymbol = config?.protocolSymbol || defaultConfig.protocolSymbol;
101
+ this.protocolPollingTime = config?.protocolPollingTime || defaultConfig.protocolPollingTime;
99
102
 
100
103
  this.promiseProxy = {
101
104
  promise: undefined,
@@ -192,10 +195,11 @@ export default class FWSocket implements FW.Socket {
192
195
  maxReconnectTimes: this.maxReconnectTimes,
193
196
  reconnectInternal: this.reconnectInternal,
194
197
  protocolSymbol: this.protocolSymbol,
198
+ protocolPollingTime: this.protocolPollingTime,
195
199
  });
196
200
  }
197
201
 
198
- async send(msg: any) {
202
+ async send(msg: string) {
199
203
  if (this.getReadyState() != WebSocket.OPEN) return;
200
204
  if (this.isPausedMessageHandle) return;
201
205
  if (!(await this.sender.onHeart?.(msg))) {
@@ -203,8 +207,19 @@ export default class FWSocket implements FW.Socket {
203
207
  if (protocolKey) {
204
208
  const symbol = Symbol(protocolKey);
205
209
  const registry = this.protocolRegistry.get(protocolKey) || new Set<Symbol>();
210
+ const protocolPolling: FW.ProtocolPolling = {
211
+ msg: msg,
212
+ schedule: FW.Entry.timeMgr.schedule(
213
+ () => {
214
+ this.sendMessage(msg);
215
+ },
216
+ this.protocolPollingTime,
217
+ cc.macro.REPEAT_FOREVER,
218
+ this,
219
+ ),
220
+ };
206
221
  this.protocolRegistry.set(protocolKey, registry.add(symbol));
207
- this.protocolContainer.set(symbol, msg);
222
+ this.protocolContainer.set(symbol, protocolPolling);
208
223
  }
209
224
  }
210
225
  this.sendMessage(msg);
@@ -234,13 +249,6 @@ export default class FWSocket implements FW.Socket {
234
249
  }
235
250
  }
236
251
  this.sendHeart();
237
-
238
- if (this.protocolContainer.size > 0) {
239
- this.protocolContainer?.forEach((msg) => {
240
- FWLog.send('协议容器轮询消息 -> ', msg);
241
- this.sendMessage(msg);
242
- });
243
- }
244
252
  },
245
253
  this.heartInternal / 1000,
246
254
  cc.macro.REPEAT_FOREVER,
@@ -305,9 +313,12 @@ export default class FWSocket implements FW.Socket {
305
313
 
306
314
  if (symbolSet && symbolSet.size > 0) {
307
315
  const [symbol] = symbolSet;
316
+ const protocolPolling = this.protocolContainer.get(symbol);
308
317
 
309
318
  symbolSet.delete(symbol);
310
319
 
320
+ protocolPolling.schedule.unSchedule();
321
+
311
322
  this.protocolContainer.delete(symbol);
312
323
 
313
324
  if (symbolSet.size === 0) {