@ives_xxz/framework 1.2.7 → 1.2.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/manager/FWLayerManager.ts +36 -9
- package/package.json +1 -1
- package/service/socket/FWSocket.ts +50 -44
|
@@ -34,6 +34,8 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
|
|
|
34
34
|
* 当前已经打开的layer缓存容器
|
|
35
35
|
*/
|
|
36
36
|
private layerMap: Map<string, FWLayerData>;
|
|
37
|
+
|
|
38
|
+
private layerProxyMap: Map<string, FW.LayerController>;
|
|
37
39
|
/**
|
|
38
40
|
* 当前所有打开Layer注册表
|
|
39
41
|
*/
|
|
@@ -46,6 +48,7 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
|
|
|
46
48
|
public initialize(): void {
|
|
47
49
|
this.layerQueue = new FWQueue<FWLayerData>();
|
|
48
50
|
this.layerMap = new Map<string, FWLayerData>();
|
|
51
|
+
this.layerProxyMap = new Map<string, FW.LayerController>();
|
|
49
52
|
this.layerRegistry = new Set<new () => FW.LayerController>();
|
|
50
53
|
this.layerStack = [];
|
|
51
54
|
}
|
|
@@ -121,11 +124,14 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
|
|
|
121
124
|
return undefined;
|
|
122
125
|
}
|
|
123
126
|
|
|
124
|
-
|
|
127
|
+
const ctr = new data.type();
|
|
125
128
|
|
|
126
129
|
/** 如果不是重复打开的Layer,不是需要添加进队列末尾的,并且已经存在于注册表中的 不进行重复打开 */
|
|
127
130
|
if (this.layerRegistry.has(data.type) && !ctr.isRepeatOpen) {
|
|
128
|
-
|
|
131
|
+
const targetController = this.findLayerProxy<Ctr>(ctr);
|
|
132
|
+
if (targetController) {
|
|
133
|
+
return targetController;
|
|
134
|
+
}
|
|
129
135
|
}
|
|
130
136
|
|
|
131
137
|
this.layerRegistry.add(data.type);
|
|
@@ -133,13 +139,16 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
|
|
|
133
139
|
if (ctr.layerType == FWSystemDefine.FWLayerType.POPUP_QUEUE && !this.layerQueue.isEmpty()) {
|
|
134
140
|
this.layerQueue.add(ctr.layerData);
|
|
135
141
|
this.layerRegistry.delete(data.type);
|
|
136
|
-
|
|
142
|
+
const targetController = this.findLayerProxy<Ctr>(ctr);
|
|
143
|
+
if (targetController) {
|
|
144
|
+
return targetController;
|
|
145
|
+
}
|
|
137
146
|
}
|
|
138
147
|
|
|
139
148
|
if (ctr.layerType != FWSystemDefine.FWLayerType.REPEAT && !ctr.isRepeatOpen) {
|
|
140
149
|
for (const [key, value] of this.layerMap) {
|
|
141
150
|
if (value.layerAssetProperty.path == ctr.layerAssetProperty.path) {
|
|
142
|
-
return this.
|
|
151
|
+
return this.findLayerProxy<Ctr>(ctr);
|
|
143
152
|
}
|
|
144
153
|
}
|
|
145
154
|
}
|
|
@@ -190,6 +199,7 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
|
|
|
190
199
|
return target[prop];
|
|
191
200
|
},
|
|
192
201
|
});
|
|
202
|
+
this.layerProxyMap.set(ctr.uuid, proxy);
|
|
193
203
|
return proxy;
|
|
194
204
|
}
|
|
195
205
|
|
|
@@ -203,11 +213,15 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
|
|
|
203
213
|
FWLog.error(`open layer failed:${data},please check param!`);
|
|
204
214
|
return undefined;
|
|
205
215
|
}
|
|
206
|
-
|
|
216
|
+
|
|
217
|
+
const ctr = new data.type();
|
|
207
218
|
|
|
208
219
|
/** 如果不是重复打开的Layer,不是需要添加进队列末尾的,并且已经存在于注册表中的 不进行重复打开 */
|
|
209
220
|
if (this.layerRegistry.has(data.type) && !ctr.isRepeatOpen) {
|
|
210
|
-
|
|
221
|
+
const targetController = this.findLayerProxy<Ctr>(ctr);
|
|
222
|
+
if (targetController) {
|
|
223
|
+
return targetController;
|
|
224
|
+
}
|
|
211
225
|
}
|
|
212
226
|
|
|
213
227
|
this.layerRegistry.add(data.type);
|
|
@@ -215,13 +229,16 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
|
|
|
215
229
|
if (ctr.layerType == FWSystemDefine.FWLayerType.POPUP_QUEUE && !this.layerQueue.isEmpty()) {
|
|
216
230
|
this.layerQueue.add(ctr.layerData);
|
|
217
231
|
this.layerRegistry.delete(data.type);
|
|
218
|
-
|
|
232
|
+
const targetController = this.findLayerProxy<Ctr>(ctr);
|
|
233
|
+
if (targetController) {
|
|
234
|
+
return targetController;
|
|
235
|
+
}
|
|
219
236
|
}
|
|
220
237
|
|
|
221
238
|
if (ctr.layerType != FWSystemDefine.FWLayerType.REPEAT && !ctr.isRepeatOpen) {
|
|
222
239
|
for (const [key, value] of this.layerMap) {
|
|
223
240
|
if (value.layerAssetProperty.path == ctr.layerAssetProperty.path) {
|
|
224
|
-
return this.
|
|
241
|
+
return this.findLayerProxy<Ctr>(ctr);
|
|
225
242
|
}
|
|
226
243
|
}
|
|
227
244
|
}
|
|
@@ -265,7 +282,6 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
|
|
|
265
282
|
}
|
|
266
283
|
|
|
267
284
|
this.layerRegistry.delete(data.type);
|
|
268
|
-
|
|
269
285
|
const proxy = new Proxy(ctr, {
|
|
270
286
|
get: (target, prop) => {
|
|
271
287
|
if (prop === 'addExternalReference') {
|
|
@@ -276,6 +292,7 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
|
|
|
276
292
|
return target[prop];
|
|
277
293
|
},
|
|
278
294
|
});
|
|
295
|
+
this.layerProxyMap.set(ctr.uuid, proxy);
|
|
279
296
|
return proxy;
|
|
280
297
|
}
|
|
281
298
|
|
|
@@ -361,6 +378,7 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
|
|
|
361
378
|
this.notifyExternalRefUpdates(ctr.layerData);
|
|
362
379
|
}
|
|
363
380
|
this.layerMap.delete(layerData.uuid);
|
|
381
|
+
this.layerProxyMap.delete(layerData.uuid);
|
|
364
382
|
}
|
|
365
383
|
}
|
|
366
384
|
|
|
@@ -388,6 +406,7 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
|
|
|
388
406
|
}
|
|
389
407
|
|
|
390
408
|
this.layerMap.delete(layerData.uuid);
|
|
409
|
+
this.layerProxyMap.delete(layerData.uuid);
|
|
391
410
|
this.layerStack.pop();
|
|
392
411
|
|
|
393
412
|
const index = this.layerStack.findIndex((v) => {
|
|
@@ -513,4 +532,12 @@ export class FWLayerManager extends FWManager implements FW.LayerManager {
|
|
|
513
532
|
this.layerMap = null;
|
|
514
533
|
this.layerQueue = null;
|
|
515
534
|
}
|
|
535
|
+
|
|
536
|
+
private findLayerProxy<Ctr extends FW.LayerController>(ctr: FW.LayerController): Ctr {
|
|
537
|
+
for (const [key, value] of this.layerMap) {
|
|
538
|
+
if (value.layerAssetProperty.path == ctr.layerAssetProperty.path) {
|
|
539
|
+
return this.layerProxyMap.get(value.uuid) as Ctr;
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
516
543
|
}
|
package/package.json
CHANGED
|
@@ -35,8 +35,6 @@ export default class FWSocket implements FW.Socket {
|
|
|
35
35
|
protected tag: string;
|
|
36
36
|
/** 是否暂停消息处理 */
|
|
37
37
|
protected isPausedMessageHandle: boolean = false;
|
|
38
|
-
/** 是否正在重连 */
|
|
39
|
-
private isReconnect: boolean = false;
|
|
40
38
|
/** 代理 */
|
|
41
39
|
private promiseProxy: FW.SocketPromiseProxy;
|
|
42
40
|
/** 协议符号 */
|
|
@@ -70,46 +68,49 @@ export default class FWSocket implements FW.Socket {
|
|
|
70
68
|
handle: FW.SocketHandle,
|
|
71
69
|
config: FW.SocketConfig,
|
|
72
70
|
): FW.SocketPromiseProxy {
|
|
73
|
-
|
|
71
|
+
try {
|
|
72
|
+
FW.Entry.timeMgr.unSchedule(this);
|
|
74
73
|
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
this.tag = tag;
|
|
75
|
+
this.address = address;
|
|
77
76
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
this.receiveTimeStamp = new Date().getTime();
|
|
84
|
-
FWLog.debug('创建socket -> ', address);
|
|
85
|
-
this.socket = new WebSocket(address);
|
|
86
|
-
this.socket.onopen = this.onSocketOpen.bind(this);
|
|
87
|
-
this.socket.onclose = this.onSocketClose.bind(this);
|
|
88
|
-
this.socket.onerror = this.onSocketError.bind(this);
|
|
89
|
-
this.socket.onmessage = this.onSocketMessage.bind(this);
|
|
90
|
-
|
|
91
|
-
this.sender = sender;
|
|
92
|
-
this.handle = handle;
|
|
93
|
-
|
|
94
|
-
const defaultConfig = FWSystemConfig.SocketDefaultConfig;
|
|
95
|
-
this.heartInternal = config?.heartInternal || defaultConfig.heartInternal;
|
|
96
|
-
this.heartTimeout = config?.heartTimeout || defaultConfig.heartTimeout;
|
|
97
|
-
this.heartWeakTime = config?.heartWeakTime || defaultConfig.heartWeakTime;
|
|
98
|
-
this.maxReconnectTimes = config?.maxReconnectTimes || defaultConfig.maxReconnectTimes;
|
|
99
|
-
this.reconnectInternal = config?.reconnectInternal || defaultConfig.reconnectInternal;
|
|
100
|
-
this.protocolSymbol = config?.protocolSymbol || defaultConfig.protocolSymbol;
|
|
101
|
-
|
|
102
|
-
this.promiseProxy = {
|
|
103
|
-
promise: undefined,
|
|
104
|
-
resolve: undefined,
|
|
105
|
-
socket: this,
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
this.promiseProxy.promise = new Promise<FW.Socket>((resolve) => {
|
|
109
|
-
this.promiseProxy.resolve = resolve;
|
|
110
|
-
});
|
|
77
|
+
this.messageEvents = {};
|
|
78
|
+
this.protocolContainer.clear();
|
|
79
|
+
this.protocolRegistry.clear();
|
|
80
|
+
this.sendHeartTimestamp = 0;
|
|
81
|
+
this.receiveTimeStamp = new Date().getTime();
|
|
111
82
|
|
|
112
|
-
|
|
83
|
+
this.socket = new WebSocket(address);
|
|
84
|
+
this.socket.onopen = this.onSocketOpen.bind(this);
|
|
85
|
+
this.socket.onclose = this.onSocketClose.bind(this);
|
|
86
|
+
this.socket.onerror = this.onSocketError.bind(this);
|
|
87
|
+
this.socket.onmessage = this.onSocketMessage.bind(this);
|
|
88
|
+
|
|
89
|
+
this.sender = sender;
|
|
90
|
+
this.handle = handle;
|
|
91
|
+
|
|
92
|
+
const defaultConfig = FWSystemConfig.SocketDefaultConfig;
|
|
93
|
+
this.heartInternal = config?.heartInternal || defaultConfig.heartInternal;
|
|
94
|
+
this.heartTimeout = config?.heartTimeout || defaultConfig.heartTimeout;
|
|
95
|
+
this.heartWeakTime = config?.heartWeakTime || defaultConfig.heartWeakTime;
|
|
96
|
+
this.maxReconnectTimes = config?.maxReconnectTimes || defaultConfig.maxReconnectTimes;
|
|
97
|
+
this.reconnectInternal = config?.reconnectInternal || defaultConfig.reconnectInternal;
|
|
98
|
+
this.protocolSymbol = config?.protocolSymbol || defaultConfig.protocolSymbol;
|
|
99
|
+
|
|
100
|
+
this.promiseProxy = {
|
|
101
|
+
promise: undefined,
|
|
102
|
+
resolve: undefined,
|
|
103
|
+
socket: this,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
this.promiseProxy.promise = new Promise<FW.Socket>((resolve) => {
|
|
107
|
+
this.promiseProxy.resolve = resolve;
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
return this.promiseProxy;
|
|
111
|
+
} catch (e) {
|
|
112
|
+
FWLog.error('创建socket失败:', e);
|
|
113
|
+
}
|
|
113
114
|
}
|
|
114
115
|
/**
|
|
115
116
|
* 注册消息事件
|
|
@@ -142,12 +143,13 @@ export default class FWSocket implements FW.Socket {
|
|
|
142
143
|
* @returns
|
|
143
144
|
*/
|
|
144
145
|
public getReadyState() {
|
|
145
|
-
return this.socket
|
|
146
|
+
return this.socket?.readyState;
|
|
146
147
|
}
|
|
147
148
|
/**
|
|
148
149
|
* 关闭连接
|
|
149
150
|
*/
|
|
150
151
|
public close() {
|
|
152
|
+
this.protocolContainer.clear();
|
|
151
153
|
FW.Entry.socketMgr.closeSocket(this);
|
|
152
154
|
}
|
|
153
155
|
|
|
@@ -159,6 +161,10 @@ export default class FWSocket implements FW.Socket {
|
|
|
159
161
|
this.isPausedMessageHandle = false;
|
|
160
162
|
}
|
|
161
163
|
|
|
164
|
+
public get isReconnect() {
|
|
165
|
+
return this.getReadyState() === WebSocket.CONNECTING;
|
|
166
|
+
}
|
|
167
|
+
|
|
162
168
|
reconnect(force?: boolean) {
|
|
163
169
|
if (force) this.reconnectTimes = 0;
|
|
164
170
|
|
|
@@ -205,7 +211,6 @@ export default class FWSocket implements FW.Socket {
|
|
|
205
211
|
this.reconnectTimes = 0;
|
|
206
212
|
this.sendHeartTimestamp = 0;
|
|
207
213
|
this.receiveTimeStamp = new Date().getTime();
|
|
208
|
-
this.isReconnect = false;
|
|
209
214
|
this.handle?.onOpen?.();
|
|
210
215
|
this.heartHandle();
|
|
211
216
|
this.promiseProxy?.resolve(this);
|
|
@@ -256,9 +261,10 @@ export default class FWSocket implements FW.Socket {
|
|
|
256
261
|
this.handle?.onClose?.();
|
|
257
262
|
FW.Entry.timeMgr.scheduleOnce(
|
|
258
263
|
() => {
|
|
259
|
-
if (
|
|
260
|
-
|
|
261
|
-
|
|
264
|
+
if (this.getReadyState() == WebSocket.CLOSING || this.getReadyState() == WebSocket.CLOSED) {
|
|
265
|
+
FWLog.debug('on close!');
|
|
266
|
+
this.reconnect();
|
|
267
|
+
}
|
|
262
268
|
},
|
|
263
269
|
this.reconnectInternal,
|
|
264
270
|
this,
|