@ives_xxz/framework 2.3.7 → 2.3.8
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/FWSocketManager.ts +8 -13
- package/package.json +2 -4
- package/service/socket/FWSocket.ts +33 -35
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import FWSocket from
|
|
2
|
-
import { FWManager } from
|
|
1
|
+
import FWSocket from '../service/socket/FWSocket';
|
|
2
|
+
import { FWManager } from './FWManager';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* socket管理器
|
|
6
6
|
*/
|
|
7
|
-
export default class FWSocketManager
|
|
8
|
-
extends FWManager
|
|
9
|
-
implements FW.SocketManager
|
|
10
|
-
{
|
|
7
|
+
export default class FWSocketManager extends FWManager implements FW.SocketManager {
|
|
11
8
|
protected socketMap: Map<string, FW.Socket>;
|
|
12
9
|
|
|
13
10
|
public initialize(): void {
|
|
@@ -71,7 +68,7 @@ export default class FWSocketManager
|
|
|
71
68
|
|
|
72
69
|
closeAll(): void {
|
|
73
70
|
for (const [key, socket] of this.socketMap) {
|
|
74
|
-
socket
|
|
71
|
+
this.closeSocket(socket);
|
|
75
72
|
}
|
|
76
73
|
this.socketMap.clear();
|
|
77
74
|
}
|
|
@@ -88,11 +85,9 @@ export default class FWSocketManager
|
|
|
88
85
|
* @param fs
|
|
89
86
|
* @returns
|
|
90
87
|
*/
|
|
91
|
-
closeSocket(fs:
|
|
92
|
-
FW.Log.debug(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
fs.socket = null;
|
|
96
|
-
this.socketMap.delete(tag);
|
|
88
|
+
closeSocket(fs: FW.Socket) {
|
|
89
|
+
FW.Log.debug('主动关闭socket!');
|
|
90
|
+
fs.close();
|
|
91
|
+
this.socketMap.delete(fs.getTag());
|
|
97
92
|
}
|
|
98
93
|
}
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FWSystemConfig } from
|
|
1
|
+
import { FWSystemConfig } from '../../config/FWSystemConfig';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* TODO 犹豫socket没有改版暂时已老的cmd字符串映射方式做,后期优化
|
|
@@ -44,6 +44,8 @@ export default class FWSocket extends FW.Service implements FW.Socket {
|
|
|
44
44
|
private protocolContainer: Map<Symbol, FW.ProtocolPolling>;
|
|
45
45
|
/** 证书 */
|
|
46
46
|
private certificate: cc.Asset;
|
|
47
|
+
/** 是否强制关闭 */
|
|
48
|
+
private forceClose: boolean;
|
|
47
49
|
|
|
48
50
|
/**
|
|
49
51
|
* 消息事件列表
|
|
@@ -70,7 +72,7 @@ export default class FWSocket extends FW.Service implements FW.Socket {
|
|
|
70
72
|
|
|
71
73
|
this.tag = tag;
|
|
72
74
|
this.address = address;
|
|
73
|
-
|
|
75
|
+
this.forceClose = false;
|
|
74
76
|
this.clear();
|
|
75
77
|
|
|
76
78
|
this.messageEvents = {};
|
|
@@ -109,14 +111,10 @@ export default class FWSocket extends FW.Service implements FW.Socket {
|
|
|
109
111
|
this.heartInternal = config?.heartInternal || defaultConfig.heartInternal;
|
|
110
112
|
this.heartTimeout = config?.heartTimeout || defaultConfig.heartTimeout;
|
|
111
113
|
this.heartWeakTime = config?.heartWeakTime || defaultConfig.heartWeakTime;
|
|
112
|
-
this.maxReconnectTimes =
|
|
113
|
-
|
|
114
|
-
this.
|
|
115
|
-
|
|
116
|
-
this.protocolSymbol =
|
|
117
|
-
config?.protocolSymbol || defaultConfig.protocolSymbol;
|
|
118
|
-
this.protocolPollingTime =
|
|
119
|
-
config?.protocolPollingTime || defaultConfig.protocolPollingTime;
|
|
114
|
+
this.maxReconnectTimes = config?.maxReconnectTimes || defaultConfig.maxReconnectTimes;
|
|
115
|
+
this.reconnectInternal = config?.reconnectInternal || defaultConfig.reconnectInternal;
|
|
116
|
+
this.protocolSymbol = config?.protocolSymbol || defaultConfig.protocolSymbol;
|
|
117
|
+
this.protocolPollingTime = config?.protocolPollingTime || defaultConfig.protocolPollingTime;
|
|
120
118
|
|
|
121
119
|
this.promiseProxy = {
|
|
122
120
|
promise: undefined,
|
|
@@ -130,7 +128,7 @@ export default class FWSocket extends FW.Service implements FW.Socket {
|
|
|
130
128
|
|
|
131
129
|
return this.promiseProxy;
|
|
132
130
|
} catch (e) {
|
|
133
|
-
FW.Log.error(
|
|
131
|
+
FW.Log.error('创建socket失败:', e);
|
|
134
132
|
}
|
|
135
133
|
}
|
|
136
134
|
/**
|
|
@@ -172,8 +170,11 @@ export default class FWSocket extends FW.Service implements FW.Socket {
|
|
|
172
170
|
*/
|
|
173
171
|
public close() {
|
|
174
172
|
this.clear();
|
|
173
|
+
this.forceClose = true;
|
|
174
|
+
this.onSocketClose();
|
|
175
|
+
this.socket?.close();
|
|
176
|
+
this.socket = null;
|
|
175
177
|
FW.Entry.timeMgr.unSchedule(this);
|
|
176
|
-
FW.Entry.socketMgr.closeSocket(this);
|
|
177
178
|
}
|
|
178
179
|
|
|
179
180
|
public pauseMessageHandle() {
|
|
@@ -208,22 +209,16 @@ export default class FWSocket extends FW.Service implements FW.Socket {
|
|
|
208
209
|
this.socket?.close();
|
|
209
210
|
this.socket = null;
|
|
210
211
|
|
|
211
|
-
this.createSocket(
|
|
212
|
-
this.
|
|
213
|
-
this.
|
|
214
|
-
this.
|
|
215
|
-
this.
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
reconnectInternal: this.reconnectInternal,
|
|
222
|
-
protocolSymbol: this.protocolSymbol,
|
|
223
|
-
protocolPollingTime: this.protocolPollingTime,
|
|
224
|
-
certificate: this.certificate,
|
|
225
|
-
},
|
|
226
|
-
);
|
|
212
|
+
this.createSocket(this.address, this.tag, this.socketSender, this.socketHandle, {
|
|
213
|
+
heartInternal: this.heartInternal,
|
|
214
|
+
heartTimeout: this.heartTimeout,
|
|
215
|
+
heartWeakTime: this.heartWeakTime,
|
|
216
|
+
maxReconnectTimes: this.maxReconnectTimes,
|
|
217
|
+
reconnectInternal: this.reconnectInternal,
|
|
218
|
+
protocolSymbol: this.protocolSymbol,
|
|
219
|
+
protocolPollingTime: this.protocolPollingTime,
|
|
220
|
+
certificate: this.certificate,
|
|
221
|
+
});
|
|
227
222
|
}
|
|
228
223
|
|
|
229
224
|
async send(msg: string) {
|
|
@@ -233,8 +228,7 @@ export default class FWSocket extends FW.Service implements FW.Socket {
|
|
|
233
228
|
const protocolKey = this.socketSender.getProtocolKey?.(msg);
|
|
234
229
|
if (protocolKey) {
|
|
235
230
|
const symbol = Symbol(protocolKey);
|
|
236
|
-
const registry =
|
|
237
|
-
this.protocolRegistry.get(protocolKey) || new Set<Symbol>();
|
|
231
|
+
const registry = this.protocolRegistry.get(protocolKey) || new Set<Symbol>();
|
|
238
232
|
const protocolPolling: FW.ProtocolPolling = {
|
|
239
233
|
msg: msg,
|
|
240
234
|
schedule: FW.Entry.timeMgr.schedule(
|
|
@@ -255,7 +249,7 @@ export default class FWSocket extends FW.Service implements FW.Socket {
|
|
|
255
249
|
|
|
256
250
|
/** 连接打开 */
|
|
257
251
|
private onSocketOpen() {
|
|
258
|
-
FW.Log.debug(
|
|
252
|
+
FW.Log.debug('on open!');
|
|
259
253
|
FW.Entry.timeMgr.unSchedule(this);
|
|
260
254
|
this.reconnectTimes = 0;
|
|
261
255
|
this.sendHeartTimestamp = 0;
|
|
@@ -299,15 +293,19 @@ export default class FWSocket extends FW.Service implements FW.Socket {
|
|
|
299
293
|
|
|
300
294
|
/** socket关闭 */
|
|
301
295
|
private onSocketClose() {
|
|
302
|
-
FW.Log.debug(
|
|
296
|
+
FW.Log.debug('on close!');
|
|
303
297
|
this.socketHandle?.onClose?.();
|
|
298
|
+
this.socket.onclose = null;
|
|
299
|
+
this.socket.onerror = null;
|
|
300
|
+
this.socket.onmessage = null;
|
|
301
|
+
this.socket.onopen = null;
|
|
304
302
|
FW.Entry.timeMgr.scheduleOnce(
|
|
305
303
|
() => {
|
|
306
304
|
if (
|
|
307
|
-
this.
|
|
308
|
-
this.getReadyState() == WebSocket.CLOSED
|
|
305
|
+
!this.forceClose &&
|
|
306
|
+
(this.getReadyState() == WebSocket.CLOSING || this.getReadyState() == WebSocket.CLOSED)
|
|
309
307
|
) {
|
|
310
|
-
FW.Log.debug(
|
|
308
|
+
FW.Log.debug('on close!');
|
|
311
309
|
this.reconnect();
|
|
312
310
|
}
|
|
313
311
|
},
|