@ives_xxz/framework 2.0.8 → 2.0.9

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