@clonegod/ttd-bsc-common 1.0.55 → 1.0.56
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.
|
@@ -23,6 +23,24 @@ class WebSocketManager {
|
|
|
23
23
|
message: anyErr === null || anyErr === void 0 ? void 0 : anyErr.message
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
+
normalizeReason(reason) {
|
|
27
|
+
try {
|
|
28
|
+
if (!reason)
|
|
29
|
+
return undefined;
|
|
30
|
+
if (typeof reason === 'string')
|
|
31
|
+
return reason;
|
|
32
|
+
if (typeof Buffer !== 'undefined' && Buffer.isBuffer(reason)) {
|
|
33
|
+
return reason.toString('utf8');
|
|
34
|
+
}
|
|
35
|
+
if (reason instanceof Uint8Array) {
|
|
36
|
+
return Buffer.from(reason).toString('utf8');
|
|
37
|
+
}
|
|
38
|
+
return String(reason);
|
|
39
|
+
}
|
|
40
|
+
catch (_a) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
26
44
|
static getInstance() {
|
|
27
45
|
if (!WebSocketManager.instance) {
|
|
28
46
|
WebSocketManager.instance = new WebSocketManager();
|
|
@@ -46,7 +64,8 @@ class WebSocketManager {
|
|
|
46
64
|
const rawWs = (_a = this.wsProvider) === null || _a === void 0 ? void 0 : _a._websocket;
|
|
47
65
|
if (rawWs === null || rawWs === void 0 ? void 0 : rawWs.on) {
|
|
48
66
|
rawWs.on('close', (code, reason) => {
|
|
49
|
-
|
|
67
|
+
const reasonText = this.normalizeReason(reason);
|
|
68
|
+
(0, dist_1.log_warn)('[WS] socket close', Object.assign(Object.assign({}, this.formatConn(wsEndpoint, network)), { code, reason: reasonText }));
|
|
50
69
|
this.handleWsDisconnection(wsEndpoint, network);
|
|
51
70
|
});
|
|
52
71
|
rawWs.on('error', (err) => {
|