@ives_xxz/framework 1.0.2 → 1.0.4

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.
Files changed (88) hide show
  1. package/FW.d.ts +39 -24
  2. package/FW.d.ts.meta +5 -5
  3. package/Framework.ts.meta +9 -9
  4. package/README.md.meta +5 -5
  5. package/animation/FWAnimation.ts.meta +9 -9
  6. package/animation/FWSkeleton.ts.meta +9 -9
  7. package/animation/FWTween.ts.meta +9 -9
  8. package/animation.meta +12 -12
  9. package/component/FWVirtualViewComponent.ts.meta +9 -9
  10. package/component.meta +12 -12
  11. package/config/FWAssetConfig.ts.meta +9 -9
  12. package/config/FWSystemConfig.ts +10 -0
  13. package/config/FWSystemConfig.ts.meta +10 -0
  14. package/config.meta +12 -12
  15. package/controller/FWLayerController.ts.meta +9 -9
  16. package/controller.meta +12 -12
  17. package/data/FWData.ts.meta +9 -9
  18. package/data.meta +12 -12
  19. package/define/FWEventDefine.ts.meta +9 -9
  20. package/define/FWSystemDefine.ts.meta +9 -9
  21. package/define.meta +12 -12
  22. package/entry/FWEntry.ts.meta +9 -9
  23. package/entry.meta +12 -12
  24. package/expand/FWCocosExpand.ts.meta +9 -9
  25. package/expand/FWDecorator.ts.meta +9 -9
  26. package/expand/FWRollingViewNesting.ts.meta +9 -9
  27. package/expand/FWTweenExpand.ts.meta +9 -9
  28. package/expand.meta +12 -12
  29. package/item/FWVirtualListItem.ts.meta +9 -9
  30. package/item.meta +12 -12
  31. package/language/FWLanguage.ts.meta +9 -9
  32. package/language/FWLanguageLabelLocalize.ts.meta +9 -9
  33. package/language/FWLanguageSkeletonLocalize.ts.meta +9 -9
  34. package/language/FWLanguageSpriteLocalize.ts.meta +9 -9
  35. package/language.meta +12 -12
  36. package/layer/FWLayer.ts.meta +9 -9
  37. package/layer.meta +12 -12
  38. package/log/FWLog.ts.meta +9 -9
  39. package/log.meta +12 -12
  40. package/logic/FWLogic.ts.meta +9 -9
  41. package/logic.meta +12 -12
  42. package/machine/FWAnimationMachine.ts.meta +9 -9
  43. package/machine/FWStateMachine.ts.meta +9 -9
  44. package/machine.meta +12 -12
  45. package/manager/FWAnimationManager.ts.meta +9 -9
  46. package/manager/FWAssetManager.ts.meta +9 -9
  47. package/manager/FWAudioManager.ts.meta +9 -9
  48. package/manager/FWBundleManager.ts.meta +9 -9
  49. package/manager/FWComponentManager.ts.meta +9 -9
  50. package/manager/FWEngineManager.ts.meta +9 -9
  51. package/manager/FWEventManager.ts.meta +9 -9
  52. package/manager/FWHotUpdateManager.ts.meta +9 -9
  53. package/manager/FWLanguageManager.ts.meta +9 -9
  54. package/manager/FWLayerManager.ts.meta +9 -9
  55. package/manager/FWManager.ts.meta +9 -9
  56. package/manager/FWObjectManager.ts.meta +9 -9
  57. package/manager/FWResManager.ts.meta +9 -9
  58. package/manager/FWSocketManager.ts +9 -14
  59. package/manager/FWSocketManager.ts.meta +9 -9
  60. package/manager/FWStateManager.ts.meta +9 -9
  61. package/manager/FWTaskManager.ts.meta +9 -9
  62. package/manager/FWTimeManager.ts.meta +9 -9
  63. package/manager/FWUiManager.ts.meta +9 -9
  64. package/manager.meta +12 -12
  65. package/package.json +2 -2
  66. package/package.json.meta +6 -0
  67. package/scene/FWScene.ts.meta +9 -9
  68. package/scene.meta +12 -12
  69. package/service/FWService.ts.meta +9 -9
  70. package/service/http/FWHttp.ts.meta +9 -9
  71. package/service/http.meta +12 -12
  72. package/service/socket/FWSocket.ts +87 -30
  73. package/service/socket/FWSocket.ts.meta +9 -9
  74. package/service/socket/FWSocketHandle.ts +8 -6
  75. package/service/socket/FWSocketHandle.ts.meta +9 -9
  76. package/service/socket/FWSocketSender.ts +4 -1
  77. package/service/socket/FWSocketSender.ts.meta +9 -9
  78. package/service/socket.meta +12 -12
  79. package/service.meta +12 -12
  80. package/state/FWState.ts.meta +9 -9
  81. package/state.meta +12 -12
  82. package/utils/FWLodash.ts.meta +9 -9
  83. package/utils/FWMask.ts.meta +9 -9
  84. package/utils/FWObject.ts.meta +9 -9
  85. package/utils/FWObjectPool.ts.meta +9 -9
  86. package/utils/FWQueue.ts.meta +9 -9
  87. package/utils/FWTask.ts.meta +9 -9
  88. package/utils.meta +12 -12
@@ -1,10 +1,10 @@
1
- {
2
- "ver": "1.1.0",
3
- "uuid": "a490a2b7-8487-4fe1-a3ce-fbb473a39530",
4
- "importer": "typescript",
5
- "isPlugin": false,
6
- "loadPluginInWeb": true,
7
- "loadPluginInNative": true,
8
- "loadPluginInEditor": false,
9
- "subMetas": {}
1
+ {
2
+ "ver": "1.1.0",
3
+ "uuid": "a490a2b7-8487-4fe1-a3ce-fbb473a39530",
4
+ "importer": "typescript",
5
+ "isPlugin": false,
6
+ "loadPluginInWeb": true,
7
+ "loadPluginInNative": true,
8
+ "loadPluginInEditor": false,
9
+ "subMetas": {}
10
10
  }
@@ -1,10 +1,10 @@
1
- {
2
- "ver": "1.1.0",
3
- "uuid": "fcb5dbc8-82ed-473e-bc81-c3b9b11a6ac6",
4
- "importer": "typescript",
5
- "isPlugin": false,
6
- "loadPluginInWeb": true,
7
- "loadPluginInNative": true,
8
- "loadPluginInEditor": false,
9
- "subMetas": {}
1
+ {
2
+ "ver": "1.1.0",
3
+ "uuid": "fcb5dbc8-82ed-473e-bc81-c3b9b11a6ac6",
4
+ "importer": "typescript",
5
+ "isPlugin": false,
6
+ "loadPluginInWeb": true,
7
+ "loadPluginInNative": true,
8
+ "loadPluginInEditor": false,
9
+ "subMetas": {}
10
10
  }
@@ -25,22 +25,17 @@ export default class FWSocketManager extends FWManager implements FW.SocketManag
25
25
  async createSocket(
26
26
  tag: string,
27
27
  address: string,
28
- sender: FWSocketSender,
29
- handle: FWSocketHandle,
30
- config: {
31
- heartTimeout: number;
32
- heartWeakTime: number;
33
- heartInternal: number;
34
- maxReconnectTimes: number;
35
- reconnectInternal: number;
36
- },
28
+ sender: FW.SocketSender,
29
+ handle: FW.SocketHandle,
30
+ config: FW.SocketConfig,
37
31
  ) {
38
32
  const proxy = new FWSocket().createSocket(address, tag, sender, handle, {
39
- heartTimeout: config?.heartTimeout,
40
- heartWeakTime: config?.heartWeakTime,
41
- heartInternal: config?.heartInternal,
42
- maxReconnectTimes: config?.maxReconnectTimes,
43
- reconnectInternal: config?.reconnectInternal,
33
+ heartTimeout: config.heartTimeout,
34
+ heartWeakTime: config.heartWeakTime,
35
+ heartInternal: config.heartInternal,
36
+ maxReconnectTimes: config.maxReconnectTimes,
37
+ reconnectInternal: config.reconnectInternal,
38
+ protocolSymbol: config.protocolSymbol,
44
39
  });
45
40
  this.socketMap.set(tag, proxy.socket);
46
41
 
@@ -1,10 +1,10 @@
1
- {
2
- "ver": "1.1.0",
3
- "uuid": "0100af82-a0d2-4359-b2b7-3a384f150ce1",
4
- "importer": "typescript",
5
- "isPlugin": false,
6
- "loadPluginInWeb": true,
7
- "loadPluginInNative": true,
8
- "loadPluginInEditor": false,
9
- "subMetas": {}
1
+ {
2
+ "ver": "1.1.0",
3
+ "uuid": "0100af82-a0d2-4359-b2b7-3a384f150ce1",
4
+ "importer": "typescript",
5
+ "isPlugin": false,
6
+ "loadPluginInWeb": true,
7
+ "loadPluginInNative": true,
8
+ "loadPluginInEditor": false,
9
+ "subMetas": {}
10
10
  }
@@ -1,10 +1,10 @@
1
- {
2
- "ver": "1.1.0",
3
- "uuid": "23fb111f-4904-4335-9433-f24147af47c9",
4
- "importer": "typescript",
5
- "isPlugin": false,
6
- "loadPluginInWeb": true,
7
- "loadPluginInNative": true,
8
- "loadPluginInEditor": false,
9
- "subMetas": {}
1
+ {
2
+ "ver": "1.1.0",
3
+ "uuid": "23fb111f-4904-4335-9433-f24147af47c9",
4
+ "importer": "typescript",
5
+ "isPlugin": false,
6
+ "loadPluginInWeb": true,
7
+ "loadPluginInNative": true,
8
+ "loadPluginInEditor": false,
9
+ "subMetas": {}
10
10
  }
@@ -1,10 +1,10 @@
1
- {
2
- "ver": "1.1.0",
3
- "uuid": "cd43dfbe-fd5d-4f6b-94de-01bc5c0a8368",
4
- "importer": "typescript",
5
- "isPlugin": false,
6
- "loadPluginInWeb": true,
7
- "loadPluginInNative": true,
8
- "loadPluginInEditor": false,
9
- "subMetas": {}
1
+ {
2
+ "ver": "1.1.0",
3
+ "uuid": "cd43dfbe-fd5d-4f6b-94de-01bc5c0a8368",
4
+ "importer": "typescript",
5
+ "isPlugin": false,
6
+ "loadPluginInWeb": true,
7
+ "loadPluginInNative": true,
8
+ "loadPluginInEditor": false,
9
+ "subMetas": {}
10
10
  }
@@ -1,10 +1,10 @@
1
- {
2
- "ver": "1.1.0",
3
- "uuid": "ef42e04a-1f21-4d92-ac3c-916af646e1f8",
4
- "importer": "typescript",
5
- "isPlugin": false,
6
- "loadPluginInWeb": true,
7
- "loadPluginInNative": true,
8
- "loadPluginInEditor": false,
9
- "subMetas": {}
1
+ {
2
+ "ver": "1.1.0",
3
+ "uuid": "ef42e04a-1f21-4d92-ac3c-916af646e1f8",
4
+ "importer": "typescript",
5
+ "isPlugin": false,
6
+ "loadPluginInWeb": true,
7
+ "loadPluginInNative": true,
8
+ "loadPluginInEditor": false,
9
+ "subMetas": {}
10
10
  }
@@ -1,10 +1,10 @@
1
- {
2
- "ver": "1.1.0",
3
- "uuid": "d33acc3d-71a7-4fe4-86fb-a939985a4d1f",
4
- "importer": "typescript",
5
- "isPlugin": false,
6
- "loadPluginInWeb": true,
7
- "loadPluginInNative": true,
8
- "loadPluginInEditor": false,
9
- "subMetas": {}
1
+ {
2
+ "ver": "1.1.0",
3
+ "uuid": "d33acc3d-71a7-4fe4-86fb-a939985a4d1f",
4
+ "importer": "typescript",
5
+ "isPlugin": false,
6
+ "loadPluginInWeb": true,
7
+ "loadPluginInNative": true,
8
+ "loadPluginInEditor": false,
9
+ "subMetas": {}
10
10
  }
package/manager.meta CHANGED
@@ -1,13 +1,13 @@
1
- {
2
- "ver": "1.1.3",
3
- "uuid": "d591f127-6089-4134-a3fd-24c263480211",
4
- "importer": "folder",
5
- "isBundle": false,
6
- "bundleName": "",
7
- "priority": 1,
8
- "compressionType": {},
9
- "optimizeHotUpdate": {},
10
- "inlineSpriteFrames": {},
11
- "isRemoteBundle": {},
12
- "subMetas": {}
1
+ {
2
+ "ver": "1.1.3",
3
+ "uuid": "d591f127-6089-4134-a3fd-24c263480211",
4
+ "importer": "folder",
5
+ "isBundle": false,
6
+ "bundleName": "",
7
+ "priority": 1,
8
+ "compressionType": {},
9
+ "optimizeHotUpdate": {},
10
+ "inlineSpriteFrames": {},
11
+ "isRemoteBundle": {},
12
+ "subMetas": {}
13
13
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ives_xxz/framework",
3
- "version": "1.0.2",
4
- "description": "cocoscreator 2.4.9 mvc framework",
3
+ "version": "1.0.4",
4
+ "description": "cocoscreator 2.x mvc framework",
5
5
  "main": "index.js",
6
6
  "keywords": [
7
7
  "123456"
@@ -0,0 +1,6 @@
1
+ {
2
+ "ver": "1.0.2",
3
+ "uuid": "beb7dd18-de47-4e37-8a42-7798786baba5",
4
+ "importer": "json",
5
+ "subMetas": {}
6
+ }
@@ -1,10 +1,10 @@
1
- {
2
- "ver": "1.1.0",
3
- "uuid": "9d78ed88-e34f-455b-9d0f-73978b74107a",
4
- "importer": "typescript",
5
- "isPlugin": false,
6
- "loadPluginInWeb": true,
7
- "loadPluginInNative": true,
8
- "loadPluginInEditor": false,
9
- "subMetas": {}
1
+ {
2
+ "ver": "1.1.0",
3
+ "uuid": "9d78ed88-e34f-455b-9d0f-73978b74107a",
4
+ "importer": "typescript",
5
+ "isPlugin": false,
6
+ "loadPluginInWeb": true,
7
+ "loadPluginInNative": true,
8
+ "loadPluginInEditor": false,
9
+ "subMetas": {}
10
10
  }
package/scene.meta CHANGED
@@ -1,13 +1,13 @@
1
- {
2
- "ver": "1.1.3",
3
- "uuid": "f8d1e84d-5adb-468b-9dcf-c84901b90bce",
4
- "importer": "folder",
5
- "isBundle": false,
6
- "bundleName": "",
7
- "priority": 1,
8
- "compressionType": {},
9
- "optimizeHotUpdate": {},
10
- "inlineSpriteFrames": {},
11
- "isRemoteBundle": {},
12
- "subMetas": {}
1
+ {
2
+ "ver": "1.1.3",
3
+ "uuid": "f8d1e84d-5adb-468b-9dcf-c84901b90bce",
4
+ "importer": "folder",
5
+ "isBundle": false,
6
+ "bundleName": "",
7
+ "priority": 1,
8
+ "compressionType": {},
9
+ "optimizeHotUpdate": {},
10
+ "inlineSpriteFrames": {},
11
+ "isRemoteBundle": {},
12
+ "subMetas": {}
13
13
  }
@@ -1,10 +1,10 @@
1
- {
2
- "ver": "1.1.0",
3
- "uuid": "02e35f42-98e4-45c5-8139-e90f226d3782",
4
- "importer": "typescript",
5
- "isPlugin": false,
6
- "loadPluginInWeb": true,
7
- "loadPluginInNative": true,
8
- "loadPluginInEditor": false,
9
- "subMetas": {}
1
+ {
2
+ "ver": "1.1.0",
3
+ "uuid": "02e35f42-98e4-45c5-8139-e90f226d3782",
4
+ "importer": "typescript",
5
+ "isPlugin": false,
6
+ "loadPluginInWeb": true,
7
+ "loadPluginInNative": true,
8
+ "loadPluginInEditor": false,
9
+ "subMetas": {}
10
10
  }
@@ -1,10 +1,10 @@
1
- {
2
- "ver": "1.1.0",
3
- "uuid": "f0ad42b9-3784-4643-9175-bffd9d96570a",
4
- "importer": "typescript",
5
- "isPlugin": false,
6
- "loadPluginInWeb": true,
7
- "loadPluginInNative": true,
8
- "loadPluginInEditor": false,
9
- "subMetas": {}
1
+ {
2
+ "ver": "1.1.0",
3
+ "uuid": "f0ad42b9-3784-4643-9175-bffd9d96570a",
4
+ "importer": "typescript",
5
+ "isPlugin": false,
6
+ "loadPluginInWeb": true,
7
+ "loadPluginInNative": true,
8
+ "loadPluginInEditor": false,
9
+ "subMetas": {}
10
10
  }
package/service/http.meta CHANGED
@@ -1,13 +1,13 @@
1
- {
2
- "ver": "1.1.3",
3
- "uuid": "8af24859-b6c3-4ead-8cf8-386570d860a8",
4
- "importer": "folder",
5
- "isBundle": false,
6
- "bundleName": "",
7
- "priority": 1,
8
- "compressionType": {},
9
- "optimizeHotUpdate": {},
10
- "inlineSpriteFrames": {},
11
- "isRemoteBundle": {},
12
- "subMetas": {}
1
+ {
2
+ "ver": "1.1.3",
3
+ "uuid": "8af24859-b6c3-4ead-8cf8-386570d860a8",
4
+ "importer": "folder",
5
+ "isBundle": false,
6
+ "bundleName": "",
7
+ "priority": 1,
8
+ "compressionType": {},
9
+ "optimizeHotUpdate": {},
10
+ "inlineSpriteFrames": {},
11
+ "isRemoteBundle": {},
12
+ "subMetas": {}
13
13
  }
@@ -1,4 +1,4 @@
1
- import Framework from '../../Framework';
1
+ import { FWSystemConfig } from '../../config/FWSystemConfig';
2
2
  import FWLog from '../../log/FWLog';
3
3
  import FWSocketHandle from './FWSocketHandle';
4
4
  import FWSocketSender from './FWSocketSender';
@@ -37,8 +37,15 @@ export default class FWSocket implements FW.Socket {
37
37
  protected isPausedMessageHandle: boolean = false;
38
38
  /** 是否正在重连 */
39
39
  private isReconnect: boolean = false;
40
-
40
+ /** 代理 */
41
41
  private promiseProxy: FW.SocketPromiseProxy;
42
+ /** 协议符号 */
43
+ private protocolSymbol: FW.Symbol;
44
+ /** 协议注册表 */
45
+ private protocolRegistry: Map<string, Set<Symbol>>;
46
+ /** 协议符号容器 */
47
+ private protocolContainer: Map<Symbol, string>;
48
+
42
49
  /**
43
50
  * 消息事件列表
44
51
  * TODO 目前没有消息协议号,暂时无用
@@ -51,24 +58,29 @@ export default class FWSocket implements FW.Socket {
51
58
 
52
59
  public initialize(): void {
53
60
  this.messageEvents = cc.js.createMap();
61
+ this.protocolContainer = new Map<Symbol, string>();
62
+ this.protocolRegistry = new Map<string, Set<Symbol>>();
54
63
  }
55
64
 
56
65
  createSocket(
57
66
  address: string,
58
67
  tag: string,
59
- sender: FWSocketSender,
60
- handle: FWSocketHandle,
61
- config: {
62
- heartInternal: number;
63
- heartTimeout: number;
64
- heartWeakTime: number;
65
- maxReconnectTimes: number;
66
- reconnectInternal: number;
67
- },
68
+ sender: FW.SocketSender,
69
+ handle: FW.SocketHandle,
70
+ config: FW.SocketConfig,
68
71
  ): FW.SocketPromiseProxy {
69
72
  FW.Entry.timeMgr.unSchedule(this);
73
+
70
74
  this.tag = tag;
71
75
  this.address = address;
76
+
77
+ this.messageEvents = {};
78
+ this.protocolContainer.clear();
79
+ this.protocolRegistry.clear();
80
+ this.isReconnect = true;
81
+ this.sendHeartTimestamp = 0;
82
+ this.receiveTimeStamp = new Date().getTime();
83
+
72
84
  this.socket = new WebSocket(address);
73
85
  this.socket.onopen = this.onSocketOpen.bind(this);
74
86
  this.socket.onclose = this.onSocketClose.bind(this);
@@ -78,15 +90,19 @@ export default class FWSocket implements FW.Socket {
78
90
  this.sender = sender;
79
91
  this.handle = handle;
80
92
 
81
- this.heartInternal = config?.heartInternal;
82
- this.heartTimeout = config?.heartTimeout;
83
- this.heartWeakTime = config?.heartWeakTime;
84
- this.maxReconnectTimes = config?.maxReconnectTimes;
93
+ const defaultConfig = FWSystemConfig.SocketDefaultConfig;
94
+ this.heartInternal = config?.heartInternal || defaultConfig.heartInternal;
95
+ this.heartTimeout = config?.heartTimeout || defaultConfig.heartTimeout;
96
+ this.heartWeakTime = config?.heartWeakTime || defaultConfig.heartWeakTime;
97
+ this.maxReconnectTimes = config?.maxReconnectTimes || defaultConfig.maxReconnectTimes;
98
+ this.reconnectInternal = config?.reconnectInternal || defaultConfig.reconnectInternal;
99
+ this.protocolSymbol = config?.protocolSymbol || defaultConfig.protocolSymbol;
85
100
 
86
101
  this.promiseProxy = {
87
102
  promise: undefined,
88
103
  socket: this,
89
104
  };
105
+
90
106
  new Promise<FWSocket>((resolve) => {
91
107
  this.promiseProxy.promise = resolve;
92
108
  });
@@ -140,7 +156,11 @@ export default class FWSocket implements FW.Socket {
140
156
  this.isPausedMessageHandle = false;
141
157
  }
142
158
 
143
- private reconnect() {
159
+ reconnect(force?: boolean) {
160
+ if (force) {
161
+ this.reconnectTimes = 0;
162
+ }
163
+
144
164
  FWLog.debug(
145
165
  `socket reconnect : reconnectTimes->${this.reconnectTimes},maxReconnectTimes->${this.maxReconnectTimes}`,
146
166
  );
@@ -148,10 +168,7 @@ export default class FWSocket implements FW.Socket {
148
168
  this.handle?.onTimeout?.();
149
169
  return;
150
170
  }
151
- FW.Entry.timeMgr.unSchedule(this);
152
- this.isReconnect = true;
153
- this.sendHeartTimestamp = 0;
154
- this.receiveTimeStamp = 0;
171
+
155
172
  this.socket.close();
156
173
  this.socket = null;
157
174
 
@@ -161,16 +178,32 @@ export default class FWSocket implements FW.Socket {
161
178
  heartWeakTime: this.heartWeakTime,
162
179
  maxReconnectTimes: this.maxReconnectTimes,
163
180
  reconnectInternal: this.reconnectInternal,
181
+ protocolSymbol: this.protocolSymbol,
164
182
  });
165
183
  }
166
184
 
185
+ async send(msg: any) {
186
+ if (this.getReadyState() != WebSocket.OPEN) return;
187
+ if (this.isPausedMessageHandle) return;
188
+ if (!(await this.sender.onHeart?.(msg))) {
189
+ const protocolKey = this.sender.getProtocolKey?.(msg);
190
+ if (protocolKey) {
191
+ const symbol = Symbol(protocolKey);
192
+ const registry = this.protocolRegistry.get(protocolKey) || new Set<Symbol>();
193
+ this.protocolRegistry.set(protocolKey, registry.add(symbol));
194
+ this.protocolContainer.set(symbol, msg);
195
+ }
196
+ }
197
+ this.sendMessage(msg);
198
+ }
199
+
167
200
  /** 连接打开 */
168
201
  private onSocketOpen() {
169
202
  FWLog.debug('on open!');
170
203
  FW.Entry.timeMgr.unSchedule(this);
171
204
  this.reconnectTimes = 0;
172
205
  this.sendHeartTimestamp = 0;
173
- this.receiveTimeStamp = 0;
206
+ this.receiveTimeStamp = new Date().getTime();
174
207
  this.isReconnect = false;
175
208
  this.handle?.onOpen?.();
176
209
  this.heartHandle();
@@ -189,6 +222,12 @@ export default class FWSocket implements FW.Socket {
189
222
  }
190
223
  }
191
224
  this.sendHeart();
225
+
226
+ if (this.protocolContainer.size > 0) {
227
+ this.protocolContainer?.forEach((msg) => {
228
+ this.sendMessage(msg);
229
+ });
230
+ }
192
231
  },
193
232
  this.heartInternal / 1000,
194
233
  cc.macro.REPEAT_FOREVER,
@@ -201,10 +240,8 @@ export default class FWSocket implements FW.Socket {
201
240
  this.sender?.sendHeart?.();
202
241
  }
203
242
 
204
- send(msg: any) {
205
- if (this.getReadyState() != WebSocket.OPEN) return;
206
- if (this.isPausedMessageHandle) return;
207
- this.socket?.send(msg);
243
+ private sendMessage(msg: any) {
244
+ this.socket?.send(this.sender.onBeforeSendingMessage?.(msg) || msg);
208
245
  }
209
246
 
210
247
  /** socket关闭 */
@@ -216,18 +253,38 @@ export default class FWSocket implements FW.Socket {
216
253
  FWLog.debug('on close!');
217
254
  this.reconnect();
218
255
  },
219
- 3,
256
+ this.reconnectInternal,
220
257
  this,
221
258
  );
222
259
  }
223
260
  /** 消息处理 */
224
- private async onSocketMessage(msg: any) {
261
+ private async onSocketMessage(originalMsg: any) {
262
+ const msg = await this.handle.onBeforeReceivingMessage(originalMsg);
263
+
225
264
  if (await this.handle?.onHeart?.(msg)) {
226
265
  this.receiveTimeStamp = new Date().getTime();
227
- } else {
228
- if (this.isPausedMessageHandle) return;
229
- this.handle?.onMessage?.(msg);
266
+ return;
230
267
  }
268
+
269
+ const protocolKey = await this.handle.getProtocolKey?.(msg);
270
+ if (protocolKey && this.protocolRegistry.has(protocolKey)) {
271
+ const symbolSet = this.protocolRegistry.get(protocolKey);
272
+
273
+ if (symbolSet && symbolSet.size > 0) {
274
+ const [symbol] = symbolSet;
275
+
276
+ symbolSet.delete(symbol);
277
+
278
+ this.protocolContainer.delete(symbol);
279
+
280
+ if (symbolSet.size === 0) {
281
+ this.protocolRegistry.delete(protocolKey);
282
+ }
283
+ }
284
+ }
285
+
286
+ if (this.isPausedMessageHandle) return;
287
+ this.handle?.onMessage?.(msg);
231
288
  }
232
289
  /** 错误处理 */
233
290
  private onSocketError(msg: any) {
@@ -1,10 +1,10 @@
1
- {
2
- "ver": "1.1.0",
3
- "uuid": "6bff4169-033b-4745-842d-fdb124b9ac6c",
4
- "importer": "typescript",
5
- "isPlugin": false,
6
- "loadPluginInWeb": true,
7
- "loadPluginInNative": true,
8
- "loadPluginInEditor": false,
9
- "subMetas": {}
1
+ {
2
+ "ver": "1.1.0",
3
+ "uuid": "6bff4169-033b-4745-842d-fdb124b9ac6c",
4
+ "importer": "typescript",
5
+ "isPlugin": false,
6
+ "loadPluginInWeb": true,
7
+ "loadPluginInNative": true,
8
+ "loadPluginInEditor": false,
9
+ "subMetas": {}
10
10
  }
@@ -1,17 +1,19 @@
1
1
  import { injectable } from 'inversify';
2
2
  @injectable()
3
- export default abstract class FWSocketHandle implements FW.Handle {
3
+ export default abstract class FWSocketHandle implements FW.SocketHandle {
4
4
  constructor() {
5
5
  this.initialize?.();
6
6
  }
7
7
  public readonly entry: FW.Entry = FW.Entry;
8
+ abstract onMessage(msg: any): void;
8
9
  initialize?();
9
10
  onDestroy?();
10
11
  onHeart?(msg: any): Promise<boolean>;
11
12
  onWeakNetWork?(): void;
12
- abstract onClose(): void;
13
- abstract onOpen(): void;
14
- abstract onMessage(msg: any): void;
15
- abstract onError(msg: any): void;
16
- abstract onTimeout(): void;
13
+ onClose?(): void;
14
+ onOpen?(): void;
15
+ onError?(msg: any): void;
16
+ onTimeout?(): void;
17
+ getProtocolKey?(msg: any): string;
18
+ onBeforeReceivingMessage?(msg: any): Promise<object>;
17
19
  }
@@ -1,10 +1,10 @@
1
- {
2
- "ver": "1.1.0",
3
- "uuid": "2e34eee4-ca3e-4ffd-9ff5-3fab23ea4f76",
4
- "importer": "typescript",
5
- "isPlugin": false,
6
- "loadPluginInWeb": true,
7
- "loadPluginInNative": true,
8
- "loadPluginInEditor": false,
9
- "subMetas": {}
1
+ {
2
+ "ver": "1.1.0",
3
+ "uuid": "2e34eee4-ca3e-4ffd-9ff5-3fab23ea4f76",
4
+ "importer": "typescript",
5
+ "isPlugin": false,
6
+ "loadPluginInWeb": true,
7
+ "loadPluginInNative": true,
8
+ "loadPluginInEditor": false,
9
+ "subMetas": {}
10
10
  }
@@ -1,7 +1,7 @@
1
1
  import { injectable } from 'inversify';
2
2
  import FWLog from '../../log/FWLog';
3
3
  @injectable()
4
- export default class FWSocketSender implements FW.Sender {
4
+ export default class FWSocketSender implements FW.SocketSender {
5
5
  constructor() {
6
6
  this.initialize?.();
7
7
  }
@@ -13,4 +13,7 @@ export default class FWSocketSender implements FW.Sender {
13
13
  send(msg: any) {
14
14
  FW.Entry.socketMgr.getSocket()?.send(msg);
15
15
  }
16
+ onHeart?(msg: any): Promise<boolean>;
17
+ onBeforeSendingMessage?(msg: any): string;
18
+ getProtocolKey?(msg: any): string;
16
19
  }
@@ -1,10 +1,10 @@
1
- {
2
- "ver": "1.1.0",
3
- "uuid": "5ef12e31-ee4f-443b-9de1-9075ecdde103",
4
- "importer": "typescript",
5
- "isPlugin": false,
6
- "loadPluginInWeb": true,
7
- "loadPluginInNative": true,
8
- "loadPluginInEditor": false,
9
- "subMetas": {}
1
+ {
2
+ "ver": "1.1.0",
3
+ "uuid": "5ef12e31-ee4f-443b-9de1-9075ecdde103",
4
+ "importer": "typescript",
5
+ "isPlugin": false,
6
+ "loadPluginInWeb": true,
7
+ "loadPluginInNative": true,
8
+ "loadPluginInEditor": false,
9
+ "subMetas": {}
10
10
  }