@ives_xxz/framework 2.3.7 → 2.3.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/FWSocketManager.ts +8 -13
- package/package.json +2 -4
- package/service/socket/FWSocket.ts +34 -37
|
@@ -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
|
/**
|
|
@@ -144,8 +142,7 @@ export default class FWSocket extends FW.Service implements FW.Socket {
|
|
|
144
142
|
|
|
145
143
|
public onDestroy(): void {
|
|
146
144
|
this.messageEvents = cc.js.createMap();
|
|
147
|
-
this.
|
|
148
|
-
this.socket = null;
|
|
145
|
+
this.close();
|
|
149
146
|
}
|
|
150
147
|
|
|
151
148
|
public getTag() {
|
|
@@ -172,8 +169,11 @@ export default class FWSocket extends FW.Service implements FW.Socket {
|
|
|
172
169
|
*/
|
|
173
170
|
public close() {
|
|
174
171
|
this.clear();
|
|
172
|
+
this.forceClose = true;
|
|
173
|
+
this.onSocketClose();
|
|
174
|
+
this.socket?.close();
|
|
175
|
+
this.socket = null;
|
|
175
176
|
FW.Entry.timeMgr.unSchedule(this);
|
|
176
|
-
FW.Entry.socketMgr.closeSocket(this);
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
public pauseMessageHandle() {
|
|
@@ -208,22 +208,16 @@ export default class FWSocket extends FW.Service implements FW.Socket {
|
|
|
208
208
|
this.socket?.close();
|
|
209
209
|
this.socket = null;
|
|
210
210
|
|
|
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
|
-
);
|
|
211
|
+
this.createSocket(this.address, this.tag, this.socketSender, this.socketHandle, {
|
|
212
|
+
heartInternal: this.heartInternal,
|
|
213
|
+
heartTimeout: this.heartTimeout,
|
|
214
|
+
heartWeakTime: this.heartWeakTime,
|
|
215
|
+
maxReconnectTimes: this.maxReconnectTimes,
|
|
216
|
+
reconnectInternal: this.reconnectInternal,
|
|
217
|
+
protocolSymbol: this.protocolSymbol,
|
|
218
|
+
protocolPollingTime: this.protocolPollingTime,
|
|
219
|
+
certificate: this.certificate,
|
|
220
|
+
});
|
|
227
221
|
}
|
|
228
222
|
|
|
229
223
|
async send(msg: string) {
|
|
@@ -233,8 +227,7 @@ export default class FWSocket extends FW.Service implements FW.Socket {
|
|
|
233
227
|
const protocolKey = this.socketSender.getProtocolKey?.(msg);
|
|
234
228
|
if (protocolKey) {
|
|
235
229
|
const symbol = Symbol(protocolKey);
|
|
236
|
-
const registry =
|
|
237
|
-
this.protocolRegistry.get(protocolKey) || new Set<Symbol>();
|
|
230
|
+
const registry = this.protocolRegistry.get(protocolKey) || new Set<Symbol>();
|
|
238
231
|
const protocolPolling: FW.ProtocolPolling = {
|
|
239
232
|
msg: msg,
|
|
240
233
|
schedule: FW.Entry.timeMgr.schedule(
|
|
@@ -255,7 +248,7 @@ export default class FWSocket extends FW.Service implements FW.Socket {
|
|
|
255
248
|
|
|
256
249
|
/** 连接打开 */
|
|
257
250
|
private onSocketOpen() {
|
|
258
|
-
FW.Log.debug(
|
|
251
|
+
FW.Log.debug('on open!');
|
|
259
252
|
FW.Entry.timeMgr.unSchedule(this);
|
|
260
253
|
this.reconnectTimes = 0;
|
|
261
254
|
this.sendHeartTimestamp = 0;
|
|
@@ -299,15 +292,19 @@ export default class FWSocket extends FW.Service implements FW.Socket {
|
|
|
299
292
|
|
|
300
293
|
/** socket关闭 */
|
|
301
294
|
private onSocketClose() {
|
|
302
|
-
FW.Log.debug(
|
|
295
|
+
FW.Log.debug('on close!');
|
|
303
296
|
this.socketHandle?.onClose?.();
|
|
297
|
+
this.socket.onclose = null;
|
|
298
|
+
this.socket.onerror = null;
|
|
299
|
+
this.socket.onmessage = null;
|
|
300
|
+
this.socket.onopen = null;
|
|
304
301
|
FW.Entry.timeMgr.scheduleOnce(
|
|
305
302
|
() => {
|
|
306
303
|
if (
|
|
307
|
-
this.
|
|
308
|
-
this.getReadyState() == WebSocket.CLOSED
|
|
304
|
+
!this.forceClose &&
|
|
305
|
+
(this.getReadyState() == WebSocket.CLOSING || this.getReadyState() == WebSocket.CLOSED)
|
|
309
306
|
) {
|
|
310
|
-
FW.Log.debug(
|
|
307
|
+
FW.Log.debug('on close!');
|
|
311
308
|
this.reconnect();
|
|
312
309
|
}
|
|
313
310
|
},
|