@ives_xxz/framework 2.0.12 → 2.0.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ives_xxz/framework",
3
- "version": "2.0.12",
3
+ "version": "2.0.13",
4
4
  "description": "cocoscreator 2.x mvc framework",
5
5
  "main": "index.js",
6
6
  "keywords": ["123456"],
@@ -1,10 +1,9 @@
1
- import { FWSystemConfig } from "../../config/FWSystemConfig";
2
- import FWService from "../FWService";
1
+ import { FWSystemConfig } from '../../config/FWSystemConfig';
3
2
 
4
3
  /**
5
4
  * TODO 犹豫socket没有改版暂时已老的cmd字符串映射方式做,后期优化
6
5
  */
7
- export default class FWSocket extends FWService implements FW.Socket {
6
+ export default class FWSocket extends FW.Service implements FW.Socket {
8
7
  /** 发送心跳时间抽 */
9
8
  private sendHeartTimestamp: number;
10
9
  /** 接收心跳时间戳 */
@@ -64,7 +63,7 @@ export default class FWSocket extends FWService implements FW.Socket {
64
63
  tag: string,
65
64
  socketSender: FW.Sender,
66
65
  socketHandle: FW.Handle,
67
- config: FW.SocketConfig
66
+ config: FW.SocketConfig,
68
67
  ): FW.SocketPromiseProxy {
69
68
  try {
70
69
  FW.Entry.timeMgr.unSchedule(this);
@@ -108,14 +107,10 @@ export default class FWSocket extends FWService implements FW.Socket {
108
107
  this.heartInternal = config?.heartInternal || defaultConfig.heartInternal;
109
108
  this.heartTimeout = config?.heartTimeout || defaultConfig.heartTimeout;
110
109
  this.heartWeakTime = config?.heartWeakTime || defaultConfig.heartWeakTime;
111
- this.maxReconnectTimes =
112
- config?.maxReconnectTimes || defaultConfig.maxReconnectTimes;
113
- this.reconnectInternal =
114
- config?.reconnectInternal || defaultConfig.reconnectInternal;
115
- this.protocolSymbol =
116
- config?.protocolSymbol || defaultConfig.protocolSymbol;
117
- this.protocolPollingTime =
118
- config?.protocolPollingTime || defaultConfig.protocolPollingTime;
110
+ this.maxReconnectTimes = config?.maxReconnectTimes || defaultConfig.maxReconnectTimes;
111
+ this.reconnectInternal = config?.reconnectInternal || defaultConfig.reconnectInternal;
112
+ this.protocolSymbol = config?.protocolSymbol || defaultConfig.protocolSymbol;
113
+ this.protocolPollingTime = config?.protocolPollingTime || defaultConfig.protocolPollingTime;
119
114
 
120
115
  this.promiseProxy = {
121
116
  promise: undefined,
@@ -129,7 +124,7 @@ export default class FWSocket extends FWService implements FW.Socket {
129
124
 
130
125
  return this.promiseProxy;
131
126
  } catch (e) {
132
- FW.Log.error("创建socket失败:", e);
127
+ FW.Log.error('创建socket失败:', e);
133
128
  }
134
129
  }
135
130
  /**
@@ -195,7 +190,7 @@ export default class FWSocket extends FWService implements FW.Socket {
195
190
  if (force) this.reconnectTimes = 0;
196
191
 
197
192
  FW.Log.debug(
198
- `socket reconnect : reconnectTimes->${this.reconnectTimes},maxReconnectTimes->${this.maxReconnectTimes}`
193
+ `socket reconnect : reconnectTimes->${this.reconnectTimes},maxReconnectTimes->${this.maxReconnectTimes}`,
199
194
  );
200
195
  if (++this.reconnectTimes >= this.maxReconnectTimes) {
201
196
  this.socketHandle?.onTimeout?.();
@@ -206,22 +201,16 @@ export default class FWSocket extends FWService implements FW.Socket {
206
201
  this.socket?.close();
207
202
  this.socket = null;
208
203
 
209
- this.createSocket(
210
- this.address,
211
- this.tag,
212
- this.socketSender,
213
- this.socketHandle,
214
- {
215
- heartInternal: this.heartInternal,
216
- heartTimeout: this.heartTimeout,
217
- heartWeakTime: this.heartWeakTime,
218
- maxReconnectTimes: this.maxReconnectTimes,
219
- reconnectInternal: this.reconnectInternal,
220
- protocolSymbol: this.protocolSymbol,
221
- protocolPollingTime: this.protocolPollingTime,
222
- certificate: this.certificate,
223
- }
224
- );
204
+ this.createSocket(this.address, this.tag, this.socketSender, this.socketHandle, {
205
+ heartInternal: this.heartInternal,
206
+ heartTimeout: this.heartTimeout,
207
+ heartWeakTime: this.heartWeakTime,
208
+ maxReconnectTimes: this.maxReconnectTimes,
209
+ reconnectInternal: this.reconnectInternal,
210
+ protocolSymbol: this.protocolSymbol,
211
+ protocolPollingTime: this.protocolPollingTime,
212
+ certificate: this.certificate,
213
+ });
225
214
  }
226
215
 
227
216
  async send(msg: string) {
@@ -231,8 +220,7 @@ export default class FWSocket extends FWService implements FW.Socket {
231
220
  const protocolKey = this.socketSender.getProtocolKey?.(msg);
232
221
  if (protocolKey) {
233
222
  const symbol = Symbol(protocolKey);
234
- const registry =
235
- this.protocolRegistry.get(protocolKey) || new Set<Symbol>();
223
+ const registry = this.protocolRegistry.get(protocolKey) || new Set<Symbol>();
236
224
  const protocolPolling: FW.ProtocolPolling = {
237
225
  msg: msg,
238
226
  schedule: FW.Entry.timeMgr.schedule(
@@ -241,7 +229,7 @@ export default class FWSocket extends FWService implements FW.Socket {
241
229
  },
242
230
  this.protocolPollingTime,
243
231
  cc.macro.REPEAT_FOREVER,
244
- this
232
+ this,
245
233
  ),
246
234
  };
247
235
  this.protocolRegistry.set(protocolKey, registry.add(symbol));
@@ -253,7 +241,7 @@ export default class FWSocket extends FWService implements FW.Socket {
253
241
 
254
242
  /** 连接打开 */
255
243
  private onSocketOpen() {
256
- FW.Log.debug("on open!");
244
+ FW.Log.debug('on open!');
257
245
  FW.Entry.timeMgr.unSchedule(this);
258
246
  this.reconnectTimes = 0;
259
247
  this.sendHeartTimestamp = 0;
@@ -278,7 +266,7 @@ export default class FWSocket extends FWService implements FW.Socket {
278
266
  },
279
267
  this.heartInternal / 1000,
280
268
  cc.macro.REPEAT_FOREVER,
281
- this
269
+ this,
282
270
  );
283
271
  }
284
272
 
@@ -297,20 +285,17 @@ export default class FWSocket extends FWService implements FW.Socket {
297
285
 
298
286
  /** socket关闭 */
299
287
  private onSocketClose() {
300
- FW.Log.debug("on close!");
288
+ FW.Log.debug('on close!');
301
289
  this.socketHandle?.onClose?.();
302
290
  FW.Entry.timeMgr.scheduleOnce(
303
291
  () => {
304
- if (
305
- this.getReadyState() == WebSocket.CLOSING ||
306
- this.getReadyState() == WebSocket.CLOSED
307
- ) {
308
- FW.Log.debug("on close!");
292
+ if (this.getReadyState() == WebSocket.CLOSING || this.getReadyState() == WebSocket.CLOSED) {
293
+ FW.Log.debug('on close!');
309
294
  this.reconnect();
310
295
  }
311
296
  },
312
297
  this.reconnectInternal,
313
- this
298
+ this,
314
299
  );
315
300
  }
316
301